Update – More Details: Retrieving Email using Exchange Web Services Managed API 2.0 (c#)

email-orange-512x512So maybe you have started to use the Exchange Web Services Managed API to get email from inboxes and wanted to get a few additional details. Below are two of the most popular issues:

 

 

How to get the message body from the EmailMessage object?

You need to do .load on the EmailMessage object. Below is a quick example:

foreach (EmailMessage msg in items.Take(10))
 {
 msg.Load();
string emailBody = msg.Body.Text;
//if your email is html, this will be the full html of the message
}

How to get plain text from the message body from the EmailMessage object?

You need to create a PropertySet that will get the body text and get the message details.  Below is a quick example:

foreach (EmailMessage msg in items.Take(10))
{ 
PropertySet emailPropSet = new PropertySet();
emailPropSet.RequestedBodyType = BodyType.Text;
emailPropSet.BasePropertySet = BasePropertySet.FirstClassProperties;
EmailMessage message = EmailMessage.Bind(service, msg.Id, emailPropSet);
string emailBody = message.Body.Text;
//yeah! the plain text version!
}
Update – More Details: Retrieving Email using Exchange Web Services Managed API 2.0 (c#)

4 thoughts on “Update – More Details: Retrieving Email using Exchange Web Services Managed API 2.0 (c#)

  1. Andy says:

    found dozens of fora describing this issue, no one delivered a solution … but you fixed it in 2 lines of code, genius !
    Thank you very much !

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s