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

Free Support Forum - aspose.com

Saving EML/MSG to HTML using memory stream


I am trying to convert email files to HTML to be rendered on a web page. I do not wish to save a file to the file system.

Can someone provide me with a sample of C# code to accomplish this? All the examples I can find involve writing to the file system.

The file contents is passed to my function as a MemoryStream.


Hi Hamish,

Thank you for posting your inquiry.

You can save a MailMessage to Memory Stream in HTML format using the following sample code. Please try it at your end and let us know if you need further help.


<span style=“font-size:
9.5pt;font-family:Consolas;mso-fareast-font-family:“Times New Roman”;
white”>MailMessage msg = <span style=“font-size:9.5pt;font-family:Consolas;mso-fareast-font-family:
“Times New Roman”;mso-bidi-font-family:Consolas;color:#2B91AF;background:white;

Aspose.Email.Mail.HtmlSaveOptions htmlSaveOptions = new Aspose.Email.Mail.HtmlSaveOptions();

htmlSaveOptions.EmbedResources = true;

MemoryStream ms = new MemoryStream();

msg.Save(ms, htmlSaveOptions);

That works perfectly, thank you. Much better than what I could come up with (stream to an Aspose.Words MHTML document, stream that to a MailMessage and then use a StreamReader to get the string).


Hi Hamish,

Thank you for sharing your feedback. Please feel free to contact us if you have any further query related to the API usage.