Html tags in body content of message file (.msg)

Hi,


We are facing problem when generating message file (.msg) programmatically with HtmlBody content. find the code sample below,

StringBuilder sb = new StringBuilder();
sb.Append("");
sb.Append(string.Format("", “some value”, “some value”));
sb.Append("
{0} : {1}
");

var mailMessage = new MailMessage();
var license = new License();
mailMessage.IsBodyHtml = true;
mailMessage.Body = sb.ToString();
var licenseLocation = String.Format("\Aspose.Email.lic");
license.SetLicense(licenseLocation);
mailMessage.Headers.Add(“X-Unsent”, “1”);
var filePath=“some file path here”;
mailMessage.Save(filePath, MailMessageSaveType.OutlookMessageFormatUnicode);

But it is showing html in body content like :

some value : some value


but it should render the html in message file.

Kindly provide us the solution for this.

Thanks & Regards,
Rahul Jain

Hi Rahul,


Thank you for contacting Aspose support team.

In the sample code you are using Body property as mailMessage.Body = sb.ToString() however HtmlBody property should be used to set the html body as given below:

mailMessage.HtmlBody = sb.ToString();

Please feel free to write us back if you have any other query in this regard.

I have tried to set HtmlBody but it’s behavior still the same. it is still showing tags in body content in message file. it works fine when I generate .eml file but I need to generate .msg file. issue is with .msg file.

Can you please provide any solution for this ?

Thanks,
Rahul Jain

Hi Rahul,

Could you please re-verify the test at your end as I am getting proper output MSG file with HTML contents without any tags. I have attached the output MSG file here for your reference and the following sample code is used:

Sample Code:

StringBuilder sb = new StringBuilder();
sb.Append("<html><body>");
sb.Append(string.Format("<table><tr><td>{0}</td><td>{1}</td></tr></table>", "some value", "some value"));
sb.Append("</body></html>");

var mailMessage = new MailMessage();
mailMessage.IsBodyHtml = true;
mailMessage.HtmlBody = sb.ToString();
mailMessage.Headers.Add("X-Unsent", "1");

var filePath = "A.msg";
mailMessage.Save(filePath, MailMessageSaveType.OutlookMessageFormatUnicode);