Reputation: 335
I am working on a Outlook AddIn where I have to get the Outlook mailbody and store it in a control which can be manipulated for my requirement. The code is like this:
Outlook.Application oApp = new Outlook.Application();
Outlook.Explorer oExplorer = oApp.ActiveExplorer();
Outlook.Selection oSelection = oExplorer.Selection;
foreach (object item in oSelection)
{
htmlEditor1.Html = mailItem.HTMLBody;
}
I checked for htmlbody format using
oldMailItem.BodyFormat.ToString();
It is giving olFormatHTML which is different from standard HTML.
How I can get the standard HTML from Outlook ?
Upvotes: 0
Views: 76
Reputation: 13601
The HTML produced by Outlook is valid XHTML markup and will display in a browser. It contains a bunch of additional Microsoft-specific tags, but these are ignored by browsers and the message will (for the most part) degrade gracefully.
If you really want to remove this extra markup and be left with just standard HTML, you could use a parser such as the Html Agility Pack to strip out any tags that have a namespace prefix (e.g. <o:p>
). From what i've seen, Outlook uses o:
, w:
, v:
and m:
to denote its mail, text, shape and math markup respectively.
As i've said, however, it is probably not necessary to remove these tags as they do not prevent the message from being displayed in a WebBrowser
control or similar.
Upvotes: 1