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

Free Support Forum - aspose.com

Converting a Words document to a .msg file via mhtml


I have an issue with page layout, specifically the left indent.

I am trying to convert a Word document to an email message. I want the email message to be editable by the user after the mail has been generated, so that text, subject, to, cc, bcc, etc… can still be modified.

I start off by converting my Word document to an aspose Words document, This document I save into a memorystream using some specific saveoptions and mhtml as format. (the other html formats yield terrible results when creating an aspose Email mailmessage)

I use this memorystream to create an aspose Email message, which I save as a /msg file. This msg file is used as a template to base a new mail on. All content is present in the mail, including the first header and last footer, tables, images and text. However, the layout is ruined. This specific Word document has a table with a negative left margin (I use the save option to support this, though it makes no difference). So when I open the mail, the table is placed differently with regards to the body text. See the attachment for details.

The same happens with the image in my header (not included in the attachment example). It loses all lkeft margin.

According to the save options this should not happen, and according to the generated mhtml file, the margins are not lost. the proper margins are included in the style tags, only they seem to be in the wrong place:

<style type=3D"text/css">@page Section1 { margin:54.45pt 7=
0.9pt 35.15pt 108.6pt; size:595.35pt 842pt }div.Section1 { page:Section1 }@=
page Section2 { margin:54.45pt 70.9pt 35.15pt 108.6pt; size:595.35pt 842pt =
}div.Section2 { page:Section2 }

the 108.6 is my margin, yet it is not applied. The actual text has the following style attributes preceding it:

<p style=3D"line-height:13pt; margin:0pt"><span style=3D"font-family:‘NS Swift’; font-size:9.5pt">

The margin:0pt seems to overwrite the 108.6.

Am I missing something, or is the margin attribute not applied properly when saving to msg format?

Kind regards.

Hi Jan,

Thanks for your inquiry. Please create a standalone runnable simple console application that helps us reproduce your problem on our end and attach it here for testing. As soon as you get this simple application ready, we’ll start investigation into your issue and provide you more information. Please also attach your input word document you’re getting this problem with here for testing.

Best regards,

Hi Awais,

Thanks for your reply. I have attached a zip containing my simple console application which has the problem isolated. Included in the project is a word file, it will be loaded automatically from where the program runs.

Hi Jan,

Thanks for the additional information. We are working over your query and will get back to you soon.

Best regards,

Hi Jan,

Thanks for being patient. I am afraid, it is not guaranteed that the output MHTML file will look exactly the same as the input Word document when converting using Aspose.Words. Aspose.Words tries to mimic the behavior of Microsoft Word as it was originally designed to work with Word documents. If you re-save this document (testmemo.docx) to MHTML format using Microsoft Word 2013, you’ll observe similar problems (MS Word produces even bad output (see attachment)). This is the expected behavior. Also, please see how Word documents are exported to HTML-based formats:

Please let me know if I can be of any further assistance.

Best regards,


Thanks for your reply and explanation.

Since the output in MHTML does include the page layout, I wonder where the layout is lost. You state that the conversion to MHTML is not guaranteed, yet I produced stable results with this part of the conversion. It wasn’t until the MHTML was opened as an Outlook email message, that the layout was messed up. So it is my conclusion that the interpretation of the MHTML stream to an Aspose email message or the subsequent conversion to an MSG file, OR the subsequent opening this MSG message as a new email cause the faulty page layout.

Will Aspose further develop this interpretation in the future, or will there be another way to convert Word Documents to Outlook email messages? Or should I conclude this is and will remain impossible using Aspose, and look for another method.

Kind regards, Paul

Hi Paul,

Thanks for your inquiry. Since your query is more related to Aspose.Email API, I am moving your thread in Aspose.Email forum where you’ll be guided appropriately.

Best regards,

Hi Paul,

We need a little time to investigate this issue in detail and will share our findings soon with you. I would request you to please spare us a little time to get back to you and appreciate your patience until then.

Hi Paul,

I was able to observe the differences in the output MHTML and converted MSG file and have reported it to our development team as NETWORKNET-34326. The issue will be investigated based on Aspose.Word’s output MHTML file and once there is some information available in this regard, we’ll update you here via this thread.


Thanks for the information. I am curious as to how this possible change will be picked up.

Kind regards

Hi Paul,

Sure we will let you know once the issue is analyzed and some feedback is received from the development team.

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

We have thoroughly investigated the issue and following are our findings:

1. Alignment: It seems that IE and Outlook use different ways to render the html. If we open converted msg file in Outlook and are using function of "See in browser" we will be able to see correct result. Also if we convert source mhtml file to eml format by AE and open it by Thunderbird - we will be able to see correct result. Also we can open source mhtml file by Word – and will be able to see the same result as in Outlook. So it is not a bug of AE.

2.Ttf attachments: These attachments are present in source mhtml file(can be seen by any text editor) and AE can't avoid adding these to attachments to the message. May be it is issue of working of Aspose.Word. As workaround could you please delete these attachments before loading in MailMessage or ask help from Aspose.Words team?

I would also like to share that new version Aspose.Email for .NET 4.1.0 is released and available for download. It contains lot of improvements and new features. You may please download it and give a try to experience the new enhancements.

I think the findings are correct. Outlook seems to ignore all style attributes when using CreateItemFromTemplate. When opening an .msg file by double clicking, the correct font is displayed, but when opening the same file through automation, de default font is shown. So it is currently impossible to open a Word document as an editable outlook mail item, I’m afraid. Sending a document directly is no problem, but giving the user the option to review and edit before sending, cannot be done at this stage.

Thanks for your thorough investigation and background information.

Hi Jan,

Thank you for your understanding and if there is anything else we can be of help to you, please feel free to write to Aspose support team.