Logo Twistround LTD  

Email Forwarding Service
Mail Utility Object


The Mail Utility Object can be used within Event Scripts or stand-alone to retrieve properties of an email. Please note, the Mail object that is passed in to the even methods have got some of the same methods, theses should be used in all cases when you operate on a mail in transit as they are more efficient due to they operating on data already in memory.

The MailUtility objects methods will not throw an exception should they fail, but instead will return the error code as a Windows Error value. 0=Success, any other number means that the method failed.

ProgramID = "trMailUtil.MailUtils"

Methods:

object.GetMailHeader([in] Filename, [out] Header) [return] LastError
Returns the RFC822 Header from the email.

object.GetMailField([in] Header, [in] FieldName , [in] Separator, [out] Field) [return] LastError
Returns a specific field from the RFC822 Mail header. If the header contain multiple fields with the same name, they will be concatenated and a separator character will be inserted between each of the values. Default Separator is a comma ",".

object.GetFieldNames([in] Header, [out] Fields) [return] LastError
Returns an array with all Field Names from the RFC822 mail header.

object.ParseAddress([in] AddressString, [out] Address) [return] LastError
Returns any SMTP addresses from a RFC822 address field (To, From, Cc, Bcc, MailTo, etc.) Any mime encoded strings are decoded prior to parsing the address field.

object.DecodeRfc1522Field([in] Field, [out] vField) [return] LastError
Decode any MIME address field into readable format.


Sample code to exercise the methods:

Option Explicit

Dim MailUtil : SET MailUtil = CreateObject("trMailUtil.MailUtils")

Dim Header, Address, Addresses

' Read the Header Fields from the Mail File
If MailUtil.GetMailHeader("C:\TEMP\73bc7fd6-a1e6401caa5a.eml", Header) <> 0 Then
    ' Failed to Read the Header
End If

' Get a Fields from the Mail Header
Call MailUtil.GetMailField(Header, "From:", ",", Address)

' Return an array of addresses from the Field
Call MailUtil.ParseAddress(Address, Addresses)

' Iterate through the address list and print each address to the screen.
For each Address in Addresses
    WScript.Echo "Address >" & Address
Next

' Decode any MIME encoded data in the Field
Dim Fld : Fld = "From: =?US-ASCII?Q?Keith_Moore?= <moore@cs.utk.edu>"

Call MailUtil.DecodeRfc1522Field(Fld, Address)

WScript.Echo Address