首先,如何获取html消息正文,然后在正文中我需要获取URL链接,其超链接,文本和URL的域名。
Well, Mailitem.HTMLBody has the HTML markup for the email item, so to get access to it:
using Outlook = Microsoft.Office.Interop.Outlook;
//---
Outlook.Application outlookApplication = new Outlook.Application();
Outlook.MailItem mailitem = (Outlook.MailItem)outlookApplication.ActiveInspector().CurrentItem;
string myhtml = mailitem.HTMLBody;
Then you need to parse out the links. Assuming they are actually coded as anchor tags, you could use a regex like the below as a starting point:
var matches = Regex.Matches(myhtml, @"<a\shref=""(?<url>.*?)"">(?<text>.*?)</a>");
foreach (Match m in matches)
{
Console.WriteLine("URL: " + m.Groups["url"].Value + " -- Text = " + m.Groups["text"].Value);
}
The above is regex is from this MSDN question
Finally, to get the domain name, you can either modify the regex above, or create a URI to do the work for you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.