EWS body plain text

JNM picture JNM · Jun 28, 2012 · Viewed 40.1k times · Source

I use EWS to get exchange emails, but how can i get plain text from email body, without html?
Now i use this:

EmailMessage item = (EmailMessage)outbox.Items[i];
item.Load();
item.Body.Text

Answer

Elijah W. Gagne picture Elijah W. Gagne · Jun 28, 2012

In the PropertySet of your item you need to set the RequestedBodyType to BodyType.Text. Here's an example:

PropertySet itempropertyset = new PropertySet(BasePropertySet.FirstClassProperties);
itempropertyset.RequestedBodyType = BodyType.Text;
ItemView itemview = new ItemView(1000);
itemview.PropertySet = itempropertyset;

FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, "subject:TODO", itemview);
Item item = findResults.FirstOrDefault();
item.Load(itempropertyset);
Console.WriteLine(item.Body);