How do I determine the format of the body of the msg file. ( example: rtf- html etc.)

Private Sub GetMessageContents(ByVal msgFile As String)
Try
Dim msg As MailMessage msg = MailMessage.Load(msgFile, MessageFormat.Msg)
Dim strFrom As String = msg.From.Address
Dim strTo As String = ""
For Each toAddress As MailAddress In msg.To
strTo += toAddress.Address & "; "
Next toAddress
Dim strCC As String = ""
For Each CCAddress As MailAddress In msg.CC
strCC += CCAddress.Address & "; "
Next CCAddress
Dim strSubject As String = msg.Subject
Dim strBody As String = msg.Body.ToString
Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Critical, "Error")
End Try
End Sub

Hi Carl,

Thank you for using Aspose.Email.

You can refer to the body type of the message body from the BodyContentType Enumerator as follow:

MailMessage msg = MailMessage.Load(“Test.msg”, MessageFormat.Msg);

BodyContentType bct = msg.BodyType;

Please give it a try at your end and let us know your feedback.

Thanks for the response. The below works however it seems to always return HTML regardless if it is a rtf formatted email or not.


Dim message As MailMessage
message = MailMessage.Load(msgFile, MessageFormat.Msg)

Dim bct = message.BodyType.ToString

I also tried the below:
Dim htmlFormat As Boolean = False
htmlFormat = message.IsBodyHtml

Hi Carl,


Thanks for the feedback.

Can you please provide us some sample files for further investigation in this regard? I have observed the issue at my end end, but just want its confirmation using your sample files. I will investigate this issue further and report it to our development team as soon as possible.

Attached are the msg files requested.

Hi Carl,


Thank you for the supporting material.

I have logged the complete details along with the MSG files in our issue tracking system (issue ID: NETWORKNET-33525) for further investigation by our development team. We will update you about resolution of this issue or any work around once we have any news in this regard.

Also, I would like to share with you that I have tried the same with MapiMessage using the following code and it does return correct results (output screenshot attached). You may not want to use MapiMessage in this case, but I thought to share my findings with you. I have accompanied these details with the logged ticket as well and development team will look into it.


MailMessage mailMsg = MailMessage.Load(“Plain Text Msg.msg”, MessageFormat.Msg);

MapiMessage mapiMsg = MapiMessage.FromFile(“Plain Text Msg.msg”);

Console.WriteLine(“MailMessage - Body Content Type: {0}”, mailMsg.BodyType.ToString());

Console.WriteLine(“MapiMessage - Body Content Type: {0}”, mapiMsg.BodyType.ToString());


mailMsg = MailMessage.Load(“Rich Text Msg.msg”, MessageFormat.Msg);

mapiMsg = MapiMessage.FromFile(“Rich Text Msg.msg”);

Console.WriteLine(“MailMessage - Body Content Type: {0}”, mailMsg.BodyType.ToString());

Console.WriteLine(“MapiMessage - Body Content Type: {0}”, mapiMsg.BodyType.ToString());


mailMsg = MailMessage.Load(“HTML Text Msg.msg”, MessageFormat.Msg);

mapiMsg = MapiMessage.FromFile(“HTML Text Msg.msg”);

Console.WriteLine(“MailMessage - Body Content Type: {0}”, mailMsg.BodyType.ToString());

Console.WriteLine(“MapiMessage - Body Content Type: {0}”, mapiMsg.BodyType.ToString());