Вопрос

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.

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top