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:
oAuth.AuthUrl = "https://accounts.google.com/o/oauth2/auth";
oAuth.TokenUrl = "https://accounts.google.com/o/oauth2/token";
oAuth.RedirectUrl = "http://localhost";
oAuth.ClientID = "421475025220-6khpgoldbdsi60fegvjdqk2bk4v19ss2.apps.googleusercontent.com";
oAuth.ClientSecret = "_4HJyAVUmH_iVrPB8pOJXjR1";
oAuth.Scope = "https://mail.google.com/";
var authorizationToken = oAuth.GetAuthorization();
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);
Have questions?
Article ID: 77, Created: December 20, 2013 at 12:43 PM, Modified: April 6, 2020 at 1:49 PM