Zip Component, Email Component, Encryption Component ActiveX Control for Zip Compression .NET Components for ASP.NET
ActiveX and .NET Components for Zip Compression, Encryption, Email, XML, S/MIME, HTML Email, Character Encoding, Digital Certificates, FTP, and more ASP Email ActiveX Component


Index of Chilkat Blog Posts

October 14, 2005

Displaying HTML Email

The Chilkat components are non-visual. (They have no user-interface elements and only present APIs to various protocols/algorithms/file formats: SMTP, POP3, IMAP, FTP, Zip, encryption, etc.) However, the question of how to display an HTML email is frequently asked. Chilkat does not provide software to display email, but you can attempt to do so using the MS Web Browser component. Here are some helpful hints provided by a Chilkat customer some time ago:

….
After tons of messing around, I basically gave up on trying to
"serve up" an .mht file. There seems to be too many issues related to it. It
seemed tooooo easy anyway. So…this seems to work PERFECT in IE-Windows,
Firefox-Windows, Safari-Mac and Firefox-Mac. I don’t care about IE-Mac

In code behind….
Dim tempContent
Dim tempFileName as string ‘will be "userId_viewEmail.htm" or
"userId_viewEmail.txt"
Dim strContentType as String ‘we need to find this to determine how to save
the file. .htm or .txt
‘we need to save a .txt file if it’s text content so the iFrame’s content is
TEXT. If we just save ‘everything as .htm, the info would display but proper
text formatting would be lost (carriage ‘returns, etc) We save the temp file
with the logged in user id. It gets overwritten each time a ‘different email
is selected to view.

Dim theEmail as Chilkat.email = New Chilkat.email
theEmail.LoadEmail("physcal path to .mht file")
If the Email.HasPlainTextBody() Then strContentType = "TEXT"
If theEmail.HasHtmlBody() Then strContentType = "HTML"
SELECT Case strContentType
Case "TEXT"
tempFileName = ".txt"
tempContent = theEmail.getPlainTextBody()
Case "HTML" ‘if we have text AND html, we will use html
tempFileName = ".htm"
tempContent = theEmail.getHtmlBody()
Case Else ’some messages don’t return anything for getPlainText/getHtmlBody
tempFileName = ".txt"
tempContent = theEmail.Body
End Select
If tempContent = "" Then tempContent = "No Content" ’show user something,
unusual, but ‘possible, normally only for emails thave have an
attachment but no message.

’save the content to a file
Dim file as file
file.create("userId_viewEmail" & tempFileName) ‘overwrites prev. file,
doesn’t matter.

In the html…
<iframe style="yourStyle" src="userId_viewEmail<%=tempFileName%>"
onLoad="resizeiFrameFunction()" />

This seems to work great. I am getting any attachment info from the .mht
file (theEmailObject) etc. and showing some links to the attachments. I’m
not saving any attachments seperatly, just showing the links to them based
on "theEmail.numAttachments", etc. Loop, grab names, file types, size, etc..
I do this so i can only show attachments that are of "acceptable type". Why
store stuff twice? we already have the attachment data in the .mht file.

Maybe someone else can use this? Thanks for your assitance.


Privacy Statement. Copyright 2000-2011 Chilkat Software, Inc. All rights reserved.
Send feedback to support@chilkatsoft.com

Components for Microsoft Windows XP, 2000, 2003 Server, Vista, Windows 7, and Windows 95/98/NT4.