3

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?

vt100
  • 923
  • 1
  • 11
  • 21

1 Answers1

2

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.

Pranav Negandhi
  • 1,594
  • 1
  • 8
  • 17
  • I am working with ui automation `System.Windows.Automation`. Message was created by something else (website) and I just have to save HTML and click the send button. You are, on another hand, showing `Microsoft.Office.Interop.Outlook` functionalities. I did not consider it yet, since I was hoping to get it done just with ui automation. With the Iterop it would probably involve saving to drafts, I am not sure yet... More to be done. Thanks for a hint. I will check it out. Probably this is the only way to go with. Thank you. – vt100 Jul 09 '15 at 11:12