The sample retrieves a POP3 email message and displays the HTML content in a WebBrowser class.

The mail message may contain the text-plain body, html-formatted body or both bodies simultaneously. In case if the mail message contains html-formatted body, you will not have to convert it to display in WebBrowser.

You will need to get the body content, replace embedded image links with image file names that are stored on the disk, and finally provide replaced html body to your webbrowser class.

You should store embedded images to the disk when receiving the message. You can do that by using the SaveAttachment event:

mailMessage.SaveAttachment = delegate (object sender, GetBodyStreamEventArgs e) {
     e.Handled = true;
     if (StringUtils.IsEmpty(e.FileName)) {
          e.FileName = GenerateUniqueFileName(); //Some embedded images do not have the e.FileName value. You will need to generate it by yourself.
     }
     e.Stream = new FileStream(@"c:\attachments\" + e.FileName, FileMode.Create);
}

string stringToDisplay = "";
 
pop3.Retrieve(msgNo, mailMessage);
 
if (mailMessage.Html != null) {
     stringToDisplay = StringUtils.GetStringsAsString(mailMessage.Html.Strings);
 
     foreach (ImageBody image in mailMessage.Images) {
         stringToDisplay := stringToDisplay.Replace("cid:" + image.ContentID, @"c:\attachments\" + image.FileName);
    }
}

If mailMessage.Html is null, please check the text body of the message:

if (mailMessage.Text != null) {
     stringToDisplay = StringUtils.GetStringsAsString(mailMessage.Text.Strings);
     //convert textToDisplay to html
}
 
webBrowser1.NavigateToString(stringToDisplay);

The current version of Clever Internet Suite does not provide the ability to convert text strings to formatted HTML. Please check the following articles:

http://www.mastercsharp.com/Article/28/text-to-html-parser
http://stackoverflow.com/questions/5680251/c-sharp-string-to-formatted-html-string
http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/c6397462-91dd-4e2e-accd-42a5d030df16

Article ID: 77, Created On: 12/20/2013, Modified: 12/20/2013