How can we help?

AxEmail.Message


Introduction

Skip to properties and methods

The Message object represents an email message. The POP3 and IMAP protocols receive email messages and the SMTP protocol can be used to send email messages.

Properties and Methods

Property Type Read/Write Description
LastError Number Read Result of the previously called function
Subject String Read/Write The Subject of the message
BodyPlainText String Read/Write The plain-text body of the message
BodyHtml String Read/Write The html body of the message
Priority Number Read/Write The Priority of the message.
FromName String Read/Write The sender’s name
FromAddress String Read/Write The sender’s email address
ReplyAddress String Read/Write The Sender’s reply-address.
ReadReceiptAddress String Read/Write Email address to send a read receipt to
Organization String Read/Write The sender’s organization name
MessageSource String Read The source of the email message
MessageHeader String Read The header of the email message
Size Number Read The sender’s organization name
Date String Read The email date
ToAddress String Read The ‘To’ address(es)
CcAddress String Read The ‘Cc’ address(es)
BccAddress String Read The ‘Bcc’ address(es)
Encoding Number Read/Write SMTP specific. Encoding used to send create this message
ID Number Read POP3 specific, The email index on the server
ImapFlags String Read The message flags reported by the IMAP protocol
ImapUID Integer Read The UID of the message reported by the IMAP protocol
ImapSequenceNumber Integer Read/Write The sequence number of the message reported by the IMAP protocol

Method Description
Clear Reset all properties to their default values
HtmlToPlainText Filter all HTML tags out of the HTML text
AddHeader Add an additional header value to the email
GetHeaderValue Get a header value from the email
AddTo Add an email recipient
AddCc Add a ‘Carbon Copy’ recipient
AddBcc Add a ‘Blind Carbon Copy’ recipient
AddAttachment Add an attachment to the email
CountAttachments Number of attachments attached to the email
GetAttachmentName Get the name of an attachment
GetAttachmentSize Get the size of an attachment
SaveAttachment Save the attachment to a file
Encode Encode an email to mime
Decode Decode the given email
LoadMIME Load a MIME file
SaveMIME Save a MIME file

LastError property

This read-only property indicates the result of the last called function.
A zero indicates: success. Any non-zero value means an error.

For a complete list of error codes, check out the following page:
www.auronsoftware.com/support/errorcodes.

Example:

Set objSmtpMail = CreateObject("AxEmail.Message")
...
objMessage.AddAttachment("C:\File.txt")
WScript.Echo "Result code:"  & objMessage.LastError
...

Subject property

This is the subject of the email message.

Example:

Set objMessage = CreateObject("AxEmail.Message")
...
objMessage.Subject = "This is an important message"
...

BodyPlainText property

This is the plain text body of the message. When sending email, set this property to the plain text part of the email message. When receiving email, this property will be set to the plain text part if a plain text part is available.

Example:

Set objEMail = CreateObject("AxEmail.Message")
Set objConstants = CreateObject("AxEmail.Components")
...
objEMail.AddAttachment "C:\MySelf.jpg"
objEMail.AddAttachment "C:\MyWife.jpg"
objEMail.BodyPlainText = "Find a picture of myself and my wife attached to this email."
objEMail.BodyHtml = "<html><body>This <img SRC="cid:1"> is me" &_"
                    <br>and <img SRC="cid:2"> my wife<br></body></html>"
...

BodyHtml property

This is the HTML body of the message. When sending email, set this property to the HTML part of the email message. When receiving email, this property will be set to the HTML part if a HTML part is available.

Example:

Set objEMail = CreateObject("AxEmail.Message")
Set objConstants = CreateObject("AxEmail.Components")
...
objEMail.AddAttachment "C:\MySelf.jpg"
objEMail.AddAttachment "C:\MyWife.jpg"
objEMail.BodyPlainText = "Find a picture of myself and my wife attached to this email."
objEMail.BodyHtml = "<html><body>This <img SRC="cid:0000001"> is me" &_"
                           <br>and <img SRC="cid:0000002"> my wife<br></body></html>"
...

Priority property

The email priority. This can be used by the email client, such as outlook, to control how to display this email.

Example:

Set objMessage = CreateObject("AxEmail.Message")
Set objConstants = CreateObject("AxEmail.Components")
...
objMessage.Priority =  objConstants.EMAIL_MESSAGE_PRIORITY_HIGH
...

FromName property

The name of the email sender. This file can be left empty.

Example:

Set objMessage = CreateObject("AxEmail.Message")
...
objMessage.FromAddress = "me@mydomain.doc"
objMessage.FromName = "This is Me"
...

FromAddress property

Example:

Set objMessage = CreateObject("AxEmail.Message")
...
objMessage.FromAddress = "me@mydomain.doc"
objMessage.FromName = "This is Me"
...

ReplyAddress property

The sender’s reply address. If this is left empty the from address will be used as the reply address.

Example:

Set objMessage = CreateObject("AxEmail.Message")
...
objMessage.ReplyAddress = "myself@mydomain.com"
...

ReadReceiptAddress property

Email address of the person who should receive a ‘read receipt’. The receipt is sent when the message recipient has displayed your message. This is useful when you are sending time-critical information, or any time you want confirmation that your message has been received.

Example:

Set objMessage = CreateObject("AxEmail.Message")
...
objMessage.ReadReceiptAddress = "myself@mydomain.com"
...

Organization property

This is the sender name of the organization of the sender.

Example:

Set objMessage = CreateObject("AxEmail.Message")
...
objMessage.Organization = "My Organization"
...

MessageSource property

This is the source of the email message.

Example:

Set objMessage = CreateObject("AxEmail.Message")
...
WScript.Echo objMessage.MessageSource
...

MessageHeader property

This is the header of the email message.

Example:

Set objMessage = CreateObject("AxEmail.Message")
...
WScript.Echo objMessage.MessageHeader
...

Size property

This is the sender name of the organization of the sender.

Example:

Set objMessage = CreateObject("AxEmail.Message")
...
WScript.Echo objMessage.Size
...

Date property

This returns the email date field.

Example:

Set objMessage = CreateObject("AxEmail.Message")
...
WScript.Echo objMessage.Date
...

ToAddress property

Returns a ‘comma seperated’ string of ‘To’ addresses for this email.

Example:

Set objMessage = CreateObject("AxEmail.Message")
...
WScript.Echo objMessage.ToAddress
WScript.Echo objMessage.CcAddress
WScript.Echo objMessage.BccAddress
...

CcAddress property

Returns a ‘comma seperated’ string of ‘Cc’ addresses for this email.

Example:

Set objMessage = CreateObject("AxEmail.Message")
...
WScript.Echo objMessage.ToAddress
WScript.Echo objMessage.CcAddress
WScript.Echo objMessage.BccAddress
...

BccAddress property

Returns a ‘comma seperated’ string of ‘Bcc’ addresses for this email.

Example:

Set objMessage = CreateObject("AxEmail.Message")
...
WScript.Echo objMessage.ToAddress
WScript.Echo objMessage.CcAddress
WScript.Echo objMessage.BccAddress
...

Encoding property

When creating a message using a specific extended ASCII encoding, like ISO-8859-6 (Arabic), use this property to set the encoding to the
proper value.

Use one of these values.

Example:

Set objMessage = CreateObject("AxEmail.Message")
Set objConstants = CreateObject("AxEmail.Components")
...
objMessage.Encoding = objConstants.EMAIL_MESSAGE_ENCODING_ARABIC
...

ID property

This is the index in the mail-drop on the POP3 server.

Example:

Set objMessage = CreateObject("AxEmail.Message")
...
WScript.Echo objMessage.ID  
...

ImapFlags property

Contains the message flags as reported by the IMAP protocol.
Find a list of the possible flags here.

Example:

Set objMessage = CreateObject("AxEmail.Message")
...
WScript.Echo objMessage.ImapFlags
WScript.Echo objMessage.ImapUID
WScript.Echo objMessage.ImapSequenceNumber
...

ImapUID property

Contains the message Unique IDentifier (UID) as reported by the IMAP protocol.

This UID uniquely identifies the message within a given mailbox. This is as opposed to the
ImapSequenceNumber.

Example:

Set objMessage = CreateObject("AxEmail.Message")
...
WScript.Echo objMessage.ImapFlags
WScript.Echo objMessage.ImapUID
WScript.Echo objMessage.ImapSequenceNumber
...

ImapSequenceNumber property

Contains the message sequence number as reported by the IMAP protocol.

The sequence number is a message index within the selected mailbox. The sequence number changes when messages with a lower sequence number are deleted.

Example:

Set objMessage = CreateObject("AxEmail.Message")
...
WScript.Echo objMessage.ImapFlags
WScript.Echo objMessage.ImapUID
WScript.Echo objMessage.ImapSequenceNumber
...

Clear method

This function resets all properties to their default values.

Parameters:

  • None

Return value:

Always 0.

Example:

Set objMessage = CreateObject("AxEmail.Message")   
...
objMessage.Clear
...

HtmlToPlainText method

This function filters all HTML tags out of HTML text.

This function can be used to set the plain text body of an e-mail message from the HTML body.

Parameters:

  • None

Return value:

Always 0.

Example:

Set objMessage = CreateObject("AxEmail.Message")   
...
objMessage.BodyHtml = "<html><body><b>Carefully crafted HTML body.</b></body></html>"
objMessage.BodyPlainText = objMessage.HtmlToPlainText(objMessage.BodyHtml)
...

AddHeader method

This function will add a header value to the email.

Parameters:

  • Name
  • Value

Return value:

Always 0.

Example:

Set objMessage = CreateObject("AxEmail.Message")   
...
objMessage.AddHeader" X-Bender"," Bite my shiny metal ass."
...

GetHeaderValue method

This function returns the given header value if it can be found.

Parameters:

  • None

Return value:

The header value.

Example:

Set objMessage = CreateObject("AxEmail.Message")   
...
WScript.Echo objMessage.GetHeader("X-UIDL")
...

AddTo method

This functions adds an email recipient to the email.

Parameters:

  • Email address
  • Display name

Return value:

Always 0.

Example:

Set objMessage = CreateObject("AxEmail.Message")   
...
objMessage.AddTo "someone@example.com", "Someone"
objMessage.AddCc "myboss@example.com", "My Boss"
objMessage.AddBcc "coworker@example.com", "Co Worker"
...

AddCc method

This function adds a recipient to the ‘Carbon Copy’ (CC) list.

Parameters:

  • Email address
  • Display name

Return value:

Always 0.

Example:

Set objMessage = CreateObject("AxEmail.Message")   
...
objMessage.AddTo "someone@example.com", "Someone"
objMessage.AddCc "myboss@example.com", "My Boss"
objMessage.AddBcc "coworker@example.com", "Co Worker"
...

AddBcc method

This function adds a recipient to the ‘Blind Carbon Copy’ (BCC) list

Parameters:

  • Email address
  • Display name

Return value:

Always 0.

Example:

Set objMessage = CreateObject("AxEmail.Message")   
...
objMessage.AddTo "someone@example.com", "Someone"
objMessage.AddCc "myboss@example.com", "My Boss"
objMessage.AddBcc "coworker@example.com", "Co Worker"
...

AddAttachment method

This function adds an attachment to the email.

Parameters:

  • Filename of the attachment
  • Display name of the attachment

Return value:

Always 0.

Example:

Set objMessage = CreateObject("AxEmail.Message")   
...
objMessage.AddAttachment "C:\Temp\file.zip", "File package"
If objMessage.LastError <> 0 Then
  WScript.Echo "Error:"  & objMessage.GetErrorDescription(objMessage.LastError)
End If
...

CountAttachments method

This function counts the number of attachments on this email

Parameters:

  • none

Return value:

The number of attachments

Example:

Set objMessage = CreateObject("AxEmail.Message")   
...
For j = 1 to objMail.CountAttachments()
  strName = objMail.GetAttachmentName(j)
  WScript.Echo "  Attachment found:"  & strName
  strPath = "C:\Temp\" & strName
  WScript.Echo "  Saving attachment to :"  & strPath
  objMail.SaveAttachment j, strPath
Next  
...

GetAttachmentName method

This function returns the filename of the attachment identified by the given ID. If the filename is not available it will return the name of the attachment.

The ID of the attachment ranges from 1 to CountAttachments

Parameters:

  • Attachment ID

Return value:

The name of the attachment

Example:

Set objMessage = CreateObject("AxEmail.Message")   
...
For j = 1 to objMail.CountAttachments()
  strName = objMail.GetAttachmentName(j)
  WScript.Echo "  Attachment found:"  & strName
  strPath = "C:\Temp\" & strName
  WScript.Echo "  Saving attachment to :"  & strPath
  objMail.SaveAttachment j, strPath
Next  
...

GetAttachmentSize method

This function returns the size of the attachment identified by the given ID. This is the size of the attachment before it is decoded.

The ID of the attachment ranges from 1 to CountAttachments

Parameters:

  • Attachment ID

Return value:

The size of the attachment

Example:

Set objMessage = CreateObject("AxEmail.Message")   
...
For j = 1 to objMail.CountAttachments
  strName = objMail.GetAttachmentName(j)
  WScript.Echo "  Attachment found:"  & strName & "; Size:"  & objMail.GetAttachmentSize(j)
  strPath = "C:\Temp\" & strName
  WScript.Echo "  Saving attachment to :"  & strPath
  objMail.SaveAttachment j, strPath
Next  
...

SaveAttachment method

This function saves the attachment identified by the given Id.

The ID of the attachment ranges from 1 to CountAttachments

Parameters:

  • Attachment ID
  • Filename to save the attachment to

Return value:

Always 0.

Example:

Set objMessage = CreateObject("AxEmail.Message")   
...
For j = 1 to objMail.CountAttachments
  strName = objMail.GetAttachmentName(j)
  WScript.Echo "  Attachment found:"  & strName
  strPath = "C:\Temp\" & strName
  WScript.Echo "  Saving attachment to :"  & strPath
  objMail.SaveAttachment j, strPath
Next  
...

Encode method

This function actually encodes the email to the MIME format.

If you are creating a MIME encoded message to send it out at a later time always call this function before calling
SaveMIME.

Parameters:

  • None

Return value:

Always 0.

Example:

Set objMessage = CreateObject("AxEmail.Message")   
...
objMessage.Encode
...

Decode method

This function will decode a MIME file.

This function is automatically called when receiving or loading a MIME encoded message. This function never needs to be called.

Parameters:

  • None

Return value:

Always 0.

Example:

Set objMessage = CreateObject("AxEmail.Message")   
...
objMessage.Decode
...

LoadMIME method

This function loads a MIME encoded email from file.

Parameters:

  • The file name to load from

Return value:

Always 0.

Example:

Set objMessage = CreateObject("AxEmail.Message")   
...
objMessage.LoadMIME "C:\Temp\Test.mime"
If objMessage.LastError <> 0 Then
  WScript.Echo "Error:"  & objMessage.GetErrorDescription(objMessage.LastError)
End If  
...

SaveMIME method

This function saves a MIME encoded file

Parameters:

  • The filename to save to

Return value:

Always 0.

Example:

Set objMessage = CreateObject("AxEmail.Message")   
...
objMessage.SaveMIME "C:\Temp\Test.mime"
If objMessage.LastError <> 0 Then
  WScript.Echo "Error:"  & objMessage.GetErrorDescription(objMessage.LastError)
End If  
...

The Message object represents an email message. The POP3 and IMAP protocols receive email messages and the SMTP protocol can be used to send email messages.