This is my code…
Dim opt As New MsgLoadOptions()
Dim msg As MailMessage = MailMessage.Load(mailPath + “email.msg”, opt)
msg.Save(mailPath + “email.mht”, SaveOptions.DefaultMhtml)
When I open up the mht file, I can see the sender (name, date etc). Is it possible to hide this when saving?
I load the MHT file into a webbrowsercontrol and I only want to show the html body.
Thank you for posting your inquiry.
You can use the MhtSaveOptions to avoid writing email headers to output MHTML. Please have a look at the following code sample and let us know if we could be of any additional help to you in this regard.
MailMessage eml = MailMessage.Load(“828929\Re- AFT good progress.eml”);
MhtSaveOptions options = new MhtSaveOptions();
options.MhtFormatOptions = MhtFormatOptions.None;
eml.Save(“828929\Re- AFT good progress.mhtml”, options);
Super - perfect! Thanks.
Is it possible to load a MailMessage (MSG) with inline images and show it in a DotNet WebBrowserControl without having to save it as MHT file first (and then load the MHT file in the WebBrowserControl)?
You can save the MailMessage to MemoryStream (using the overloaded version of Save method) and then load the stream in browser as byte array. A simple search on Google resulted in this help over StackOverflow and will be sufficient for your requirements. Please let us know if you need any further assistance in this regard.
Dim message As MailMessage = MailMessage.Load("email.msg")
Using msgStream As New MemoryStream
Dim opt As New HtmlSaveOptions
msgStream.Position = 0
Dim arr As Byte() = msgStream.ToArray
web.DocumentStream = New MemoryStream(arr)
You are welcome.