To display HTML email (or any email) in a C# / VB.NET application, you can make use of the Microsoft HTML Object Library. In Visual Studio, select Project –> "Add Reference…", then select the "COM" tab, then scroll down and select the "Microsoft HTML Object Library". A WebBrowser control should appear in your toolbox. Drop an instance of it onto your form. The default Dock property setting is "Fill", so you may wish to create a container for it. (I used a SplitContainer.)
C# to Display HTML Email
// To display the email in an embedded web browser, use CreateTempMht.
// This saves the email to a .mht file.
// The MHT file that is created will not contain any of the email's
// attachments, if any existed. Also, if the email was plain-text,
// the MHT file will be saved such that the plain-text is converted
// to HTML using pre-formatted text ("pre" HTML tags) allowing it to
// be displayed correctly in a WebBrowser.
// If an empty string is passed to CreateTempMht, the filepath of a temporary
// file is returned. Otherwise, the input string is returned.
string mhtFilename = email.CreateTempMht("c:/MailClientData/temp/temp.mht");
if (mhtFilename == null)
{
MessageBox.Show(email.LastErrorText);
return;
}
// Load the MHT in the WebBrowser:
webBrowser1.Navigate("file:///C:/MailClientData/temp/temp.mht");
VB.NET to Display HTML Email
' To display the email in an embedded web browser, use CreateTempMht.
' This saves the email to a .mht file.
' The MHT file that is created will not contain any of the email's
' attachments, if any existed. Also, if the email was plain-text,
' the MHT file will be saved such that the plain-text is converted
' to HTML using pre-formatted text ("pre" HTML tags) allowing it to
' be displayed correctly in a WebBrowser.
' If an empty string is passed to CreateTempMht, the filepath of a temporary
' file is returned. Otherwise, the input string is returned.
Dim mhtFilename As String
mhtFilename = email.CreateTempMht("c:/MailClientData/temp/temp.mht")
If (mhtFilename = Nothing) Then
MessageBox.Show(email.LastErrorText)
Exit Sub
End If
' Load the MHT in the WebBrowser:
WebBrowser1.Navigate("file:///C:/MailClientData/temp/temp.mht")