EWS Client not getting BodyText

Hey,

I am evaluating your product and have an issue with the Exchange Server Client.

I am fetching Emails using ExchangeServer and am not able to get the BodyText.
It always gets only BodyHtml Property.

I tried to get the Emails with some other protocols like POP/IMAP both provides me both the properties BodyHTML and BodyText too. Only EWS is not able to get the same.

I have attached the Image so you can get the idea from it. Also, the code that I am using for getting the MailMessage.

Dim objMailMessage As MailMessage = Nothing
objMailMessage = objExsClient.GetMessage(strMsgID)
If Not IsNothing(objMailMessage) Then
	If IsNothing(objMailMessage.BodyText) Then
		strBody = objMailMessage.BodyHtml
	Else
		strBody = objMailMessage.BodyText
	End If
End If

Hi Harsh,

After some investigation, we concluded that unfortunately, this doesn’t seem to be possible.

You see, the EWS allows to set the type of body which you want to retrieve (HTML or Text).
However, if you set it to Text it will not retrieve the text/plain body, instead, it will extract the text from HTML. This is not the same as what you see in EML and MSG files where the plain text is often different from the HTML.

Anyway, perhaps as a solution for your requirement you could load the HTML body into some HTML library (like HtmlAgilityPack) and retrieve the text elements.

I hope this helps.

Regards,
Mario

Hey Mario,

Thanks for your quick response.
I would like to clarify some points here.

  • I am not using Microsoft.Exchange.WebServices.Data in my project. I am using only your GemBox.Email.Exchange namespace for ExchangeClient.
  • As you suggested the BodyType property. Neither we are setting that property nor your ExchangeClient has that one.
  • We don’t want to use any other third-party dependencies (HtmlAgilityPack) except yours.

I am posting the whole code that I am using to get the Body of the Message.
As we want BodyText mainly not the whole message in HTML.

Public Sub LoadExsMessages()
	Dim strBody As String = ""
	Try
		Dim objEXsClient As ExchangeClient = New ExchangeClient(Me.Host)
		objEXsClient.Authenticate(Me.UserName, Me.Password)
		If Not IsNothing(objEXsClient) Then
			For Each objExMsgInfo As ExchangeMessageInfo In objEXsClient.SearchMessages("Inbox", 0, 10, "SUBJECT ""User Preferences""")
				Dim objMailMsg As MailMessage = objEXsClient.GetMessage(objExMsgInfo.ExchangeMessageId)
				If Not IsNothing(objMailMsg) Then
					If IsNothing(objMailMsg.BodyText) Then
						strBody = objMailMsg.BodyHtml
					Else
						strBody = objMailMsg.BodyText
					End If
				End If
			Next
		End If
	Catch ex As Exception
		Throw ex
	End Try
End Sub

I hope the code will help you with the further processes.

Regards,
Harsh

Hi Harsh,

Please try again with this bugfix:
https://www.gemboxsoftware.com/email/nightlybuilds/GBE17v1007.zip

Or this NuGet package:
Install-Package GemBox.Email -Version 17.0.1007-hotfix

Does this solve your issue?

Regards,
Mario

Hey Mario,

Thanks.
It solved my issue.