We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

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:

<span style=“font-size:
10.0pt;font-family:“Courier New”;color:#2B91AF;mso-no-proof:yes”>StringBuilder<span style=“font-size:10.0pt;font-family:“Courier New”;mso-no-proof:yes”> sb = newStringBuilder();<o:p></o:p>

sb.Append("

");

sb.Append(string.Format("

", "some value", "some value"));

sb.Append("

{0} : {1}
");

var mailMessage = newMailMessage();

mailMessage.IsBodyHtml = true;

mailMessage.HtmlBody = sb.ToString();

mailMessage.Headers.Add("X-Unsent", "1");

var filePath = "A.msg";

mailMessage.Save(filePath, MailMessageSaveType.OutlookMessageFormatUnicode);