Search code examples
c#.netoutlookui-automationmicrosoft-ui-automation

Get HTML from Outlook's message editor - ControlType.Document


I am trying to fetch HTML from the Outlook. Text format is set to HTML and that is what will be received by the exchange server after I send it.

I am able to get text using:

if (e.Current.ControlType == ControlType.Document && e.Current.Name == subject+" - Message")
{
       TextPattern v = (TextPattern)e.GetCurrentPattern(TextPattern.Pattern);
       System.Console.WriteLine("DOC:"+ v.DocumentRange.GetText(-1));
}

Is there any way to read HTML from the editor using .NET automation features?


Solution

  • I think you're working with the wrong class. I extracted the following snippet from an example on the Microsoft support website. HTMLBody is a getter/setter (although it is used as a setter in this example).

    Outlook.MailItemClass mItem = (Outlook.MailItemClass)doc.MailEnvelope.Item;
    mItem.Subject = strSubject;
    mItem.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;
    mItem.HTMLBody = GetString(strBody);
    

    The full article is available here.