Displaying HTML-formatted messages (Part 3)
Advanced topics
Summary: Briefly covers usage
of optional paramaters of previously discussed methods. 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
GetBodyWithEmbeddedObjectsEx and RemoveMessageDirectory methods
support additional parameters that may be useful for advanced applications.
Making e-mail safe and secure
Overriding defaults
By default, GetBodyWithEmbeddedObjectsEx 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 GetBodyWithEmbeddedObjectsEx 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 GetBodyWithEmbeddedObjectsEx
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 GetBodyWithEmbeddedObjectsEx 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 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.
We're also setting PathBuildingMode parameter to 4 (DIRECT and INDEX hybrid mode) which provides more accurate processing of inline attachments with the same filename. E-mails can have multiple inline attachments
with the same filename (e.g. picture.gif) and to avoid saving them under the same filename (thus overwriting some of them), we need to be sure that each file is saved under a unique
filename by adding a suffix.
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.
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, 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) objWebBrowser.Document.Write objMsg.GetBodyWithEmbeddedObjectsEx(, , , 4, , ) 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-2024, AfterLogic Corporation. All rights reserved.