MailBee. NET Objects Tutorials

Display HTML/plain text message in web application

Since web applications run in the web browser which renders HTML, not plain-text, you should convert plain-text data into HTML to enable viewing this data in the browser. This also applies to desktop applications which render data in the HTML container.

MailBee provides you with the ability to automatically convert plain-text content into HTML during the message parsing. For the purpose of tuning the message parsing process, MailMessage class provides Parser property.

C#

MailMessage msg = pop.DownloadEntireMessage(1);
msg.Parser.PlainToHtmlMode = PlainToHtmlAutoConvert.IfNoHtml;

VB.NET

Dim msg As MailMessage =  pop.DownloadEntireMessage(1) 
msg.Parser.PlainToHtmlMode = PlainToHtmlAutoConvert.IfNoHtml

The node above downloads the message from the server and tells MailBee to automatically convert the plain-text body of the message into HTML (if the message does not already have HTML version). Thus, you will get an HTML message which can be displayed in ASP.NET application as follows:

C#

Response.Write(msg.BodyHtmlText);

VB.NET

Response.Write(msg.BodyHtmlText)

If you also need to display message headers in HTML container, you can use HeadersAsHtml property which replaces “<”, “>”, “&” and “"” characters in all headers of the message with their HTML representation:

C#

msg.Parser.HeadersAsHtml = true;
Response.Write("From: " + msg.From.ToString());

VB.NET

msg.Parser.HeadersAsHtml = True
Response.Write("From: " + msg.From.ToString())