Saving EML/MSG to HTML using memory stream

Hi,

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.

Cheers,
Hamish

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.

Code:

MailMessage msg = MailMessage.Load("1.eml");
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).


Thanks!

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.