Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EWS body plain text

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 
like image 913
JNM Avatar asked Jun 28 '12 11:06

JNM


2 Answers

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); 
like image 86
Elijah W. Gagne Avatar answered Sep 27 '22 22:09

Elijah W. Gagne


In powershell:

    .........     $message = [Microsoft.Exchange.WebServices.Data.EmailMessage]::Bind($event.MessageData,$itmId)  $PropertySet = New-Object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties) $PropertySet.RequestedBodyType = [Microsoft.Exchange.WebServices.Data.BodyType]::Text $message.Load($PropertySet) $bodyText= $message.Body.toString() 
like image 21
Liz Barraza Avatar answered Sep 27 '22 23:09

Liz Barraza