MailMessageSaveHtmlAndRelatedFiles Method |
Namespace: MailBee.Mime
Exception | Condition |
---|---|
MailBeeInvalidArgumentException | filename is a null reference (Nothing in Visual Basic) or an empty string. |
MailBeeIOException | An I/O error occurred and ThrowExceptions is true. |
All links to the embedded objects (pictures, CSS tables, etc) contained in the generated HTML file are automatically corrected to match the filenames assigned to these files when they were saved to disk.
By default, embedded objects are saved in the same folder where the HTML file resides. To store related files in another folder, set msg.Parser.WorkingFolder property prior to calling any method which can save related files.
Seting msg.Parser.WorkingFolder property value to some absolute path is mandatory in case if the HMTL in the e-mail message contains BASE tag (relative paths in URLs won't work correctly when BASE tag is present). Luckily, BASE tag is commonly not used in e-mail nowadays.
You can also tell MailBee to automatically save the message as HTML file to disk when the message gets parsed by setting msg.Parser.AutoSaveHtmlMode = HtmlMessageAutoSaving.SaveMessageHtmAndRelatedFiles (assuming msg is MailMessage instance). Another option is using GetHtmlAndSaveRelatedFiles method and its overloads.
If you're getting non-Latin characters not being displayed correctly in resulting HTML files, consider setting WriteUtf8ByteOrderMark to true (like in the sample code below).
Note |
---|
You may consider much simpler way of showing HTML e-mails with embedded images by direct base64 embedding of these images into the HTML. Use GetHtmlWithBase64EncodedRelatedFiles method for that. You can then save its result into an HTML file. |
// To use the code below, import MailBee namespaces at the top of your code. using MailBee; using MailBee.Mime; // The actual code (put it into a method of your class). MailMessage msg = new MailMessage(); msg.LoadMessage(@"C:\Docs\TestMail.eml"); msg.Parser.WriteUtf8ByteOrderMark = true; msg.SaveHtmlAndRelatedFiles(@"C:\Temp\doc.htm");