Formatting header when saving message to MHTML?

Are there any formatting options available when saving an email message to MHTML and using MailMessageSaveOptions.WriteHeaderToMht?


My two primary concerns in order of importance are:

1) There is no spacing between the headerLineTitle span and the headerLineText span. For example, you will get lines like “To:John Doe” or “Subject:Test” with no space after the colon. This looks bad.

2) You use a fixed format for the send date in the header (possibly RFC2822?). But this is uncommonly used when someone would actually print an email in Outlook. Ideally I would like to specify the desired standard or custom .NET DateTime format string here.

In general, I’d like the header to more closely represent what you get when printing from Outlook since our intention is to do the MSG->MHTML->PDF conversion process.

Hi Barry,


Thanks for writing to us.

1. Using the latest version of Aspose.Email for .NET 2.7.0, I was not able to observe the issue of no space. Could you please try it using the latest version of Aspose.Email and let us know your feedback.. Please try it at your end and let us know your feedback.

2. Aspose.Email provides the MhtMessageFormatter class to format the output MHT (see Convert to Mht Format topic). You can use MhtMessageFormatter’s DateTimeFormat property to format the DateTime using the following code. Please let us know your feedback then.

MailMessage msg = MailMessage.Load(“Testing MHT formatting.msg”);

MhtMessageFormatter mailFormatter = new MhtMessageFormatter();

mailFormatter.DateTimeFormat = "ddd dd.MM.yyyy hh:mm";

mailFormatter.Format(msg);

msg.Save("Testing MHT formatting.mht", MessageFormat.Mht, MailMessageSaveOptions.None);


#2 - Thank you that works, but it would have been infinitely clearer to have the formatter in the msg.Save method since that is when you know formatting a message for MHTML is relevant.

#1 - The issue is that I'm taking the generated MHTML, loading it in Aspose.Words, and then saving to PDF. In that process spacing is not preserved. You can observe the same thing by saving the generated MHTML to PDF using Aspose.Words or just loading it in Microsoft Word. Only when loading the MHT file in Internet Explorer do you see spacing between the header title and text based on the CSS width. I should be able to work around this issue by adding spaces using the MhtMessageFormatter.

Hi Barry,


Thank you for the feedback.

@ No.2: It’s good to know you found the MHTMessageFormatter class useful for your requirements.

@ No.1: I analyzed the output of both Outlook and Aspose.Email and was able to find the differences between the two. For time being, you may use the MhtMessageFormatter as a workaround method to introduce spaces as required. I’ll discuss this with our development team for a default behaviour implementation similar to outlook’s output. I’ll keep you posted here in case of any possible modification in this regard.

One more related issue to this:


If you use MailMessageSaveOptions.WriteHeaderToMht or use a custom MHTMessageFormatter and set the CssStyles property, the CSS for the header is not correctly inserted into the MHT unless the original email’s HtmlBody has a section.

When receiving messages from users of webmail products such as Gmail, the message’s HTML version often is just an HTML body fragment without the expected structure. For these messages, you do not get the proper styling of the MHT header because the styles were silently omitted.

Hi Barry,

We are very sorry for the late response.

Could you please provide us some sample console application with such a test message file and its MHT output for our analysis. We’ll look into it and see if this can be modified as per the expected behavior. Looking forward to assist you further.

Sorry, why did you delete my question?

Hi Sergey,

Your post hasn’t been deleted but separated as a new thread here. Please follow the new thread for further correspondence with our support team.

Thanks you!

You are welcome.