Message Object

The Message object represents a single e-mail message. You can use methods and properties of the Message object to examine or set message attributes and content.

When retrieving a message with the POP3 or IMAP4 object, downloaded message is parsed and stored in the Message object's property values.

When creating a message to be sent by the SMTP object, the Message object's property values are encoded and assembled to produce e-mail message data.

Thus, many properties of the Message object can be both read (when downloading and displaying messages) and set (when composing and sending messages).

Syntax

Message.property|method

 

Collections
Attachments The collection of attachments to the message.
Properties
AddressDelimiter Specifies the delimiter to be used to separate individual items when returning e-mail addresses' or friendly names' strings.
AltBodyEncoding Specifies which encoding method to use for the message alternative body.
AutoEncodeHeaders Sets or gets if MailBee should automatically encode headers and attachment filenames with international characters.
AltBodyText Contains alternative plain-text body of the message if the primary body is HTML-formatted.
BCCAddr The e-mail addresses of the blind-carbon-copy recipients.
BodyEncoding Specifies which encoding method to use for the message primary body.
BodyFormat Indicates the primary body format: Plain-Text, HTML, etc.
BodyText The primary body text.
CCAddr The e-mail addresses of the carbon-copy recipients.
CCFriendlyName The friendly names of the carbon-copy recipients.
Charset Specifies the charset of the message body.
ContentType The "Content-Type:" message header value.
Date The date and time when the message was composed.
Enable8bitEncoding Indicates whether 8bit characters are permitted in the message body.
FromAddr The e-mail address of the sender.
FromFriendlyName The friendly name of the sender.
HasAttachments Indicates whether the message has any attachments.
MessageID The "Message-ID:" message header value.
MinimalRebuild Restricts possible modifications of the message to operations with its headers.
PureCCAddr The e-mail addresses (with friendly names removed) of the carbon-copy recipients.
PureFromAddr The e-mail address (with friendly name removed) of the sender.
PureToAddr The e-mail addresses (with friendly names removed) of the primary recipients.
RawBody The entire message source including the headers, all the bodies and attachments.
RawHeader Returns the entire message header block.
Received The "Received:" message header value.
ReplyToAddr The e-mail address of the entity specified to receive all replies to the message.
ReturnPath The e-mail address from which the message was actually sent.
Size The size of the entire message in bytes.
SpecialBodyContentType Contains the value of Content-Type header of the non-standard text body part of the message.
SpecialBodyHeaders Specifies additional headers to be put into the header section of the non-standard text body part of the message.
SpecialBodyText Contains the non-standard body of the message.
Subject The subject of the message.
ToAddr The e-mail addresses of the primary recipients.
ToFriendlyName The friendly names of the primary recipients.
XMailer The "X-Mailer:" message header value.
Methods
AddAttachment Attaches a file to the message.
AddHeader Adds custom header to the message.
AddMemoryAttachment Attaches a data from memory as file to the message.
AddStringAttachment Attaches a data from string as file to the message.
ConvertCharset Converts the supplied string encoded in the given charset into another charset.
DecodeMstnef Extracts attachments from MS-TNEF (winmail.dat) attachment if any, removes MS-TNEF attachments from Attachments collection, and returns the number of extracted files.
EncodeHeaderText Encodes a string using the specified charset encoding.
EscapeIdnDomain Encodes specified text string (e-mail address) to allow using international characters in domain name.
GetBodyWithEmbeddedObjects Saves embedded pictures (and other objects referenced in the message HTML body) to temporary files and returns modified HTML body text where paths to the embedded objects are replaced with paths to the the temporary files.
GetBodyWithEmbeddedObjectsEx In addition to GetBodyWithEmbeddedObjects method functionality, provides more options and allows using virtual paths and dynamic URLs to reference embedded objects in the HTML body.
GetCodepageFromCharset Returns codepage number for the specified charset.
GetDateFromString Converts the specified date and time string into Date type.
GetFileAsArray Returns the contents of the specified file as Byte Array. In ASP, you can use this method to download files to the clients.
GetFriendlyName Extracts and returns the friendly name from the specified full e-mail address
GetHeader Returns the value of the specified message header.
GetHtmlFromPlain Returns the specified plain-text adapted for display in HTML browser.
GetMD5Digest Returns the MD5 Digest value of the specified string.
GetMD5DigestOfArray Returns the MD5 Digest value of the specified byte array.
GetMessageDirectoryPath Returns path to the directory where the embedded objects were saved during GetBodyWithEmbeddedObjects or GetBodyWithEmbeddedObjectsEx method call.
GetPlainFromHtml Converts the specified HTML text into plain-text.
GetPureAddr Extracts and returns the pure e-mail address from the specified full e-mail address
ImportAltBodyText Loads the specified file contents into the message alternative body.
ImportBodyText Loads the specified file contents into the message primary body and, optionally, scans the loaded HTML body for embedded objects and appends them as attachments.
ImportFromFile Loads entire message from the specified file.
ImportFromMemory Loads entire message from the specified byte array.
MakeAltBody Creates the alternative plain-text body from the current value of the HTML body.
MessageDirectoryExists Indicates whether the directory for the embedded objects storage exists.
RemoveCharsetFromBody Removes the meta tag containing the charset declaration of the document from the HTML body, and returns the charset removed.
RemoveHeader Removes custom header from the message.
RemoveMessageDirectory Deletes the directory for the embedded objects storage.
SaveMessage Saves the entire message to disk in .EML format.
ToUTF8 Returns the specified string converted in UTF-8 charset.
UnescapeIdnDomain Decodes the e-mail address string with Punycode-encoded domain part (IDN) into human-readable form.
ValidateEmailAddress Tests whether the specified e-mail address is correct.
WriteStringToFile Writes the specified string into the specified file.

 

Remarks

To retrieve a message (and the Message object) from the POP3 server, you can use RetrieveSingleMessage or RetrieveSingleMessageHeaders methods of the POP3 object. RetrieveSingleMessageHeaders method returns a message with only headers set so you can use it for message preview purposes.

The IMAP4 object does also include RetrieveSingleMessage and RetrieveSingleMessageHeaders methods.

The POP3 object can also return multiple messages at once within the Messages collection of Message objects. Refer to RetrieveMessages and RetrieveHeaders methods documentation for details. With the IMAP4 object, however, it is more efficient to preview multiple messages as the Envelopes collection of Envelope objects.

When composing a new message, you can get a reference to the Message object from SMTP.Message property.

Finally, you can create the Message object directly in the code:

[Visual Basic]
Set objMessage = CreateObject("MailBee.Message")

[ASP]
Set objMessage = Server.CreateObject("MailBee.Message")

This is useful when using stand-alone methods of the Message object (such as GetFileAsArray), or when you want to extract a message from another message (e.g. to obtain forwarded message from the attachment).

 

Example

The following example retrieves a message from the POP3 server and displays it. The sample is presented separately in Visual Basic version and ASP version since they differ quite enough.

[Visual Basic]
Dim objPOP3, objMsg

' Create POP3 object
Set objPOP3 = CreateObject("MailBee.POP3")

' Unlock POP3 object
objPOP3.LicenseKey = "put your license key here"

' Set POP3 server name
objPOP3.ServerName = "mail.server.com"

' Set user credentials
objPOP3.UserName = "username"
objPOP3.Password = "password"

' Download first message in the mailbox
Set objMsg = objPOP3.RetrieveSingleMessage(1)

If objPOP3.IsError Then
  ' Display error information
  MsgBox "Error #" & objPOP3.ErrCode & ", " & objPOP3.ErrDesc
Else
  ' Display the message
  MsgBox _
    "From: " & objMsg.FromAddr & vbCrLf & _
    "To: " & objMsg.ToAddr & vbCrLf & _
    "Subject: " & objMsg.Subject & vbCrLf & _
    "Date: " & objMsg.GetDateFromString(objMsg.Date) & vbCrLf & vbCrLf & _
    objMsg.BodyText
End If

' Close the connection
objPOP3.Disconnect

 

[ASP]
<%
Dim objPOP3, objMsg

' Create POP3 object
Set objPOP3 = Server.CreateObject("MailBee.POP3")

' Unlock POP3 object
objPOP3.LicenseKey = "put your license key here"

' Set POP3 server name
objPOP3.ServerName = "mail.server.com"

' Set user credentials
objPOP3.UserName = "username"
objPOP3.Password = "password"

' Download first message in the mailbox
Set objMsg = objPOP3.RetrieveSingleMessage(1)

If objPOP3.IsError Then
  ' Display error information
  Response.Write "Error #" & objPOP3.ErrCode & ", " & objPOP3.ErrDesc
Else
  ' Display the message.
  ' We use Server.HTMLEncode to convert '<' and '>'
  ' characters which can disturb the output if they
  ' are contained in the message headers.
  Response.Write _
    "From: " & Server.HTMLEncode(objMsg.FromAddr) & "<br>" & _
    "To: " & Server.HTMLEncode(objMsg.ToAddr) & "<br>" & _
    "Subject: " & Server.HTMLEncode(objMsg.Subject) & "<br>" & _
    "Date: " & objMsg.GetDateFromString(objMsg.Date) & "<br><br>" & _
    objMsg.BodyText
End If

' Close the connection
objPOP3.Disconnect
%>

 

See Also

SMTP Object, POP3 Object, IMAP4 Object

 


Send feedback to AfterLogic
Copyright © 2002-2024, AfterLogic Corporation. All rights reserved.