Displaying HTML-formatted messages (Part 3)
Advanced topics
Summary: Briefly covers usage
of optional paramaters of previously discussed methods. Highlights using MessageCensor
component for better e-mail security. Lists additional methods useful for embedded
objects management.
Tutorial map:
Part 1 - Quickly display e-mail with
inline pictures
Part 2 - Removing temporary files after
use
Part 3 - Advanced topics
GetBodyWithEmbeddedObjects and RemoveMessageDirectory methods
support additional parameters that may be useful for advanced applications.
Making e-mail safe and secure
Censoring of HTML content is possible through using MessageCensor component
(Censor parameter). Because viruses are common example of embedded objects,
censoring controlled by GetBodyWithEmbeddedObjects method not only cuts
unsafe code from HTML content, but also prevents saving these objects to disk
(this is important because many antivirus programs interfere with applications
writing virus code to disk).
Note: MessageCensor is a separate FREE component
not included in MailBee package. You may get it from MailBee
web site.
Overriding defaults
By default, GetBodyWithEmbeddedObjects creates message folder in the
current user's temporary folder (usually something like "C:\Documents and
Settings\UserName\Local Settings\Temp", but this is OS-dependent). However,
TempDirectoryPath parameter of GetBodyWithEmbeddedObjects method
allows you to use any path for the temporary folder.
You can also provide custom name for message directory created by MailBee in
the temporary folder (use MessageDirectoryName parameter of GetBodyWithEmbeddedObjects
method). By default, message directory name is generated as MD5-digest of Message-ID.
This is fine for most applications but you may override this if you need.
RemoveMessageDirectory method supports MessageDirectoryPath parameter,
which overrides message directory path stored in the Message object.
You may use it for deleting message directory if corresponding Message
object (and the path stored inside) already gone. You may even delete any (not
related to MailBee) directories. Also, there is an option to delete only the
directory content but not delete the directory itself - DeleteContentOnly
parameter.
Getting info on message directory path
Once GetBodyWithEmbeddedObjects was called, you may obtain path to the
message directory using GetMessageDirectoryPath method. You may store
this value and then pass it as a value of MessageDirectoryPath parameter
of RemoveMessageDirectory method. If GetMessageDirectoryPath returns
empty string, this means the message has no embedded objects (or they were censored
out if censoring is used) and corresponding message directory was not created.
You may check whether message directory exists and it is a folder (not a file)
using MessageDirectoryExists method.
To manually get MD5-digest of Message-ID (by default, this digest is used as
a message directory name), use GetMD5Digest method. You may also use
it for getting MD5 digests of any strings.
All together
The sample below displays the message on Command1_Click event and cleans-up
on Form_Unload. Now the Message object is a not a global variable. Instead,
only the message directory path is stored in global variable. Censoring with
default rules is also used.
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 strPath Private Sub Command1_Click() Dim objPOP3, objCensor, objMsg Set objCensor = CreateObject("MC.MessageCensor") ' license key is not required because MessageCensor is a free component objCensor.SetDefaults Set objPOP3 = CreateObject("MailBee.POP3") objPOP3.LicenseKey = "put your license key here" If objPOP3.Connect("pop.iforum.com", 110, "webmaildemo@iforum.com", "demo") Then If objPOP3.MessageCount > 0 Then Set objMsg = objPOP3.RetrieveSingleMessage(1) objWebBrowser.Document.Write objMsg.GetBodyWithEmbeddedObjects (, , objCensor) strPath = objMsg.GetMessageDirectoryPath End If objPOP3.Disconnect Else MsgBox objPOP3.ErrDesc End If End Sub Private Sub Form_Load() strPath = "" objWebBrowser.Navigate "about:blank" End Sub Private Sub Form_Unload(Cancel As Integer) Dim objMsg If strPath <> "" Then Set objMsg = CreateObject("MailBee.Message") objMsg.RemoveMessageDirectory strPath End If End Sub
See Also:
GetBodyWithEmbeddedObjects
Method
RemoveMessageDirectory
Method
GetMessageDirectoryPath
Method
MessageDirectoryExists
Method
GetMD5Digest Method
Copyright © 2002-2008, AfterLogic Corporation. All rights reserved.