Displaying HTML-formatted messages (Part 1)
Quickly display e-mail
with inline pictures
Summary: Discusses
displaying HTML-formatted e-mail messages in a WebBrowser control, including
handling embedded objects.
Tutorial map:
Part 1 - Quickly display e-mail with inline pictures
Part 2 - Removing temporary files after
use
Part 3 - Advanced topics
HTML messages often contain embedded pictures, sounds, scripts, style-sheets,
etc. In order correctly render HTML content, these embedded objects must be
saved to disk first.
GetBodyWithEmbeddedObjectsEx method of MailBee.Message object saves
the message's embedded objects into temporary location and modifies URLs of
these objects in HTML source to match their new locations. GetBodyWithEmbeddedObjectsEx
returns modified HTML body text, original Message.BodyText property value
is not affected.
By default all embedded objects are saved somewhere in the current user's temporary
folder.
Note: When the message is received from POP3 server,
no temporary files are created (MailBee processes e-mails "in-memory"
manner). Only explicit call of GetBodyWithEmbeddedObjectsEx method may
cause some files to be saved.
GetBodyWithEmbeddedObjectsEx method supports several parameters but all
of them are optional. So, in the simplest case HTML message may be displayed
like in the code below:
Code example:
' Assume objWebBrowser is a valid WebBrowser control ' (It's included in Microsoft Internet Controls type library). ' This sample is for VB only, ASP samples are discussed in another tutorial Dim objPOP3, objMsg Set objPOP3 = CreateObject("MailBee.POP3") objPOP3.LicenseKey = "put your license key here" If objPOP3.Connect("mail.server.com", 110, "user", "pass") Then If objPOP3.MessageCount > 0 Then Set objMsg = objPOP3.RetrieveSingleMessage(1) ' This code is required to create Document object within objWebBrowser objWebBrowser.Navigate "about:blank" While objWebBrowser.Document Is Nothing DoEvents Wend ' Print prepared body text into WebBrowser control (objWebBrowser object) objWebBrowser.Document.Write objMsg.GetBodyWithEmbeddedObjectsEx End If objPOP3.Disconnect Else MsgBox objPOP3.ErrDesc End If
See Also:
Part 2
(Removing temporary files after use)
GetBodyWithEmbeddedObjectsEx
Method
Copyright © 2002-2024, AfterLogic Corporation. All rights reserved.