EWS emails with HTML BodyType

I have an application that periodically polls an 2010 exchange server email inbox for emails with a certain subject.

I am using c#, .Net 3.5 in VS2008. I can successfully connected to, retrieve all the emails I require.

If the Body of the email contains XML which is validated with an xsd, usually this is working fine but when the email has a BodyType of HTML the xml tags are not displayed and it fails the xsd validation.

If I do a show source on the email body the xml tags are all there. My question is, how do I get the actual xml text and not the html text?
I initiate the service using

m_Service = new ExchangeService(ExchangeVersion.Exchange2010);

I am returning the search results using this…

public void getEmails(string searchType)
{
   ItemView itemView = new ItemView(int.MaxValue);
   SearchFilter searchFilter = new SearchFilter.ContainsSubstring(EmailMessageSchema.Subject, EmailSubject);
   SearchResults = Service.FindItems(GetFolderName(searchType), searchFilter, itemView);
}

and loading the individual emails

foreach (Item item in SearchResults)
{
    item.Load();
    EmailMessage mes = (EmailMessage)item;
    string emailBody = item.Body.Text;
}
Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s