So 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: Additional info for message body data here. […]
LikeLike
Thanks this article help me lot
LikeLike
Thanks, glad you enjoyed!
LikeLike
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 !
LikeLike