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

March 9, 2006

Display HTML Email in ASP, ASP.NET


I am using your ActiveX components for processing email via IMAP. All works great, but I have run into an interesting problem. While stepping through some new features of my application, I noticed “embedded” objects (like images, etc…) are not recognized as attachments. After digging through your very helpful documentation, I am now able to retrieve these objects using the various “getRelated….” Methods. While processing email, my application saves the “htmlbody” to a database field and I can later retrieve and display it via a web a interface (.asp side of my application). But when it comes to these “embedded objects”, how can I display them properly. When I view the “htmlbody” source I see references to cid: etc…

One option is to convert the CID links to filesystem links, and use Chilkat MHT to unpack the email to temporary files on the web server. Here is some sample VB6 code that demonstrates it. The methods/properties are identical for .NET, so the same applies…

<font size=2 face=\"courier\">
    ‘ Make sure the Chilkat Email or IMAP component is unlocked.
    Dim mailman As New ChilkatMailMan2
    mailman.UnlockComponent "test"
    ‘ For the example, we’re simply loading an email object from a text file..
    Dim email As New ChilkatEmail2
    email.LoadEml "htmlEmail.txt"
    ‘ Prepare the email for extraction to MHT.
    ‘ email2 will be such that all sender/recipient info is eliminated,
    ‘ as well as subject, attachments, etc., leaving only the HTML and related items.
    Dim email2 As New ChilkatEmail2
    If (email.HasHtmlBody()) Then
        htmlStr = email.GetHtmlBody()
        ‘ Convert CID links to filesystem links.
        n = email.NumRelatedItems
        For i = 0 To n - 1
            fname = email.GetRelatedFilename(i)
            email2.AddRelatedData email.GetRelatedData(i), fname
            htmlStr = Replace(htmlStr, "cid:" + email.GetRelatedContentID(i), "parts/" + fname)
        email2.SetHtmlBody htmlStr
        email2.SetHtmlBody email.Body
    End If
    ‘ Get the MIME source of the email.  (MHT is nothing more than MIME source with a .mht extension)
    mhtStr = email2.GetMime()
    Dim mht As New ChilkatMHT
    mht.UnlockComponent "test"
    ‘ Unpack from an in-memory MHT string to a "temp" subdirectory.  Related parts will
    ‘ be placed in "temp/parts".
    mht.UnpackMhtStr mhtStr, "temp", "test.html", "parts"

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

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