MailMessageGetHtmlAndSaveRelatedFiles Method
Extracts the HTML body of the message, saves the attached inline pictures and other related files to disk, and return the modified HTML body.

Namespace: MailBee.Mime
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.5.0 build 687 for .NET 4.5
Syntax
public string GetHtmlAndSaveRelatedFiles()

Return Value

Type: String
A string containing the HTML body which is altered in such a way so that all Content-ID references (cid:) are replaced with paths to the related files as they were saved by this method.
Remarks

The inline objects referenced in the HTML body of the message (i.e. embedded objects) are saved into a sub-folder in a folder denoted by MailMessage.Parser.WorkingFolder property. The links to the embedded objects in the returned HTML data are corrected automatically. The value of BodyHtmlText property is left intact.

This overload creates a message folder in MailMessage.Parser.WorkingFolder but does not delete it when this MailMessage object gets disposed. If this is not what you want, you can use GetHtmlAndSaveRelatedFiles(string, VirtualMappingType, MessageFolderBehavior) overload to specify another MessageFolderBehavior mode OR just remove the message folder when it's no longer needed. For the latter, you need to know the filepath of the message folder. To get it, call MailMessage.Parser.GetMessageFolder method after the message folder has been created during GetHtmlAndSaveRelatedFiles(String, VirtualMappingType, MessageFolderBehavior) method call.

If you're saving the resulting HTML file NOT in the current folder, it's strongly recommended to explicitly set MailMessage.Parser.WorkingFolder prior to calling this method. Otherwise, you won't get embedded images displayed as relative paths in the saved HTML file and on the filesystem won't match. Or, just use SaveHtmlAndRelatedFiles(String) method.

Note 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.
Examples
This sample creates an HTML file from the e-mail message. The related files will also be saved into the same location.
Note Note
You can also use SaveHtmlAndRelatedFiles(String) method to save messages as HTML pages.
using System.IO;
using MailBee;
using MailBee.Mime;

class Sample
{
    static void Main(string[] args)
    {
        // Load the message from file.
        MailMessage msg = new MailMessage();
        msg.LoadMessage(@"C:\Docs\TestMail.eml");

        // Set the folder where all related files should be saved.
        msg.Parser.WorkingFolder = @"C:\Temp";

        // Generate an HTML file.
        using (StreamWriter sw = new StreamWriter(@"C:\Temp\web_page.htm", false))
        {
            sw.Write(msg.GetHtmlAndSaveRelatedFiles());
        }
    }
}
See Also