MailBee.NET Objects 3.1

MailMessage.GetHtmlAndSaveRelatedFiles 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.

public string GetHtmlAndSaveRelatedFiles();

Return Value

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 the 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.

Example

This sample creates an HTML file from the e-mail message. The related files will also be saved into the same location.

Note   You can also use SaveHtmlAndRelatedFiles method to save messages as HTML pages.
[C#]
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());
        }
    }
}
[Visual Basic]
Imports System.IO
Imports MailBee
Imports MailBee.Mime

Module Sample
    Sub Main(ByVal args As String())
        ' Load the message from file.
        Dim msg As 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.
        Dim sw As StreamWriter
        Try
            sw = New StreamWriter("C:\Temp\web_page.htm", False)
            sw.Write(msg.GetHtmlAndSaveRelatedFiles())
        Finally
            If Not sw Is Nothing Then
                sw.Close()
            End If
        End Try
    End Sub
End Module

See Also

MailMessage Class | MailBee.Mime Namespace | MailMessage.GetHtmlAndSaveRelatedFiles Overload List