Domanda

first of all, How to get the html message body, then in the body i need to fetch the URL links, its hyper link, text and the domain name of the URL.

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top