Knowledgebase
Cannot retrieve HTML content from emails (.NET)
Posted by Mohammad Jawwad on 15 November 2008 03:35 AM
Email messages contain messages from several MIME types including "text/html" and "text/plain". An easy way to retrieve the appropriate content type without worrying about the underlying mime type is as follows :

=========================================================================

Imap i = new Imap("hostname", "username", "password");
i.Debug = true;
i.LicenseKey = // license key
i.Connect();
IEnumerator e = i.GetMessages();
while (e.MoveNext())
{
MimeMessage message = (MimeMessage)e.Current;
MimeMessage m0 = message.GetPart(0) as MimeMessage;
MimeMessage m1 = message.GetPart(1) as MimeMessage;
Console.WriteLine("Plain Body : \n" + m0.GetBody());
Console.WriteLine("Html Body : \n" + m1.GetBody());
}
i.Disconnect();

=========================================================================

Cast each result of getMessage() method call to MimeMessage instead of EmailMessage or HtmlEmailMessage. Use the getParts() method on each of the MimeMessage objects
to retrieve both the plaintext part and the html part. In this manner the caller does not have to worry about the mime type of the email message.
(108 vote(s))
This article was helpful
This article was not helpful

Comments (0)
Post a new comment
 
 
Full Name:
Email:
Comments:
Help Desk Software by Kayako fusion