The built-in functions in the MailMessage class provide the ability to create and read email messages for SMTP or POP3 sessions.
The MailMessage class offers the following functionality:
-
MailMessage New ()
- Returns a new MailMessage instance, or undefined if an error occured.
Email Recipient Types
-
PRIMARY_RECIPIENT
- Used to indicate that the specified recipient is a primary recipient, ie, the To: field
-
CC_RECIPIENT
- Used to indicate that the specified recipient is a CC recipient, ie, the CC: field
-
BCC_RECIPIENT
- Used to indicate that the specified recipient is a BCC recipient, ie, the BCC: field
Content Type Encoding Constants
-
ENCODING_7BIT
- Specifies 7 bit encoding for the content
-
ENCODING_8BIT
- Specifies 8 bit encoding for the content
-
ENCODING_QUOTEDPRINTABLE
- Specifies quoted printable encoding for the content
-
ENCODING_BASE64
- Specifies base64 encoding for the content
Content Disposition Type Constants
-
CONTENT_INLINE
- Specifies inline content
-
CONTENT_ATTACHMENT
- Specifies attachment content
-
Integer AddContent(
String content, Integer contentTransferEncodingType )
- Adds inline content to a multipart email message.
-
Integer AddFileAttachment(
String attachmentName, String fileName, Integer contentTransferEncodingType, String mimeType )
- Same as calling AddFilePart (attachmentName, filename, CONTENT_ATTACHMENT, contentTransferEncodingType,"text/plain" ) .
-
Integer AddFilePart(
String partName, String filename, Integer contentDisposition, Integer contentEncoding, String mimeType )
- Adds data to a multi-part email from a file.
-
Integer AddRecipient(
Integer recipientType, String emailAddress, String fullName )
- Add a recipient to an email.
-
Integer AddStringAttachment(
String attachmentName, String stringData, Integer contentTransferEncodingType, String mimeType )
- Same as calling AddStringPart (attachmentName, stringData, CONTENT_INLINE, contentTransferEncodingType,"text/plain" ) .
-
Integer AddStringPart(
String partName, String stringData, Integer contentDisposition, Integer contentEncoding, String mimeType )
- Adds string data to a multi-part email.
-
String GetContent()
- Retrieves the body of the message.
-
String GetContentType()
- retrieves the email content type.
-
Date GetDate()
- Retrieves the date of the email.
-
String GetHeaderField(
String fieldName )
- Retrieves the field data for a specific header field.
-
List GetHeaders()
- Returns a list of all the email message headers.
-
String GetLastError()
- Retrieve the a string for the last error code.
-
List GetMultipartContent()
- Retrieves a list of the multipart content.
-
String GetRawMessage()
- Retrieves the full text of the raw message.
-
RecArray GetRecipients(
)
- Returns a RecArray of recipients.
-
String GetSender()
- Retrieves the sender of the email.
-
String GetSubject()
- Returns the subject from the email.
-
Boolean IsMultipart()
- Checks if the message is a multi-part email.
-
Integer SetContent(
String content, Integer contentEncoding )
- Adds content to the body of the email.
-
Integer SetContentType(
String contentType )
- Set the email content type.
-
Integer SetDate(
Date date )
- Sets the date of the email.
-
Integer SetHeaderField(
String fieldname, String fieldData )
- Sets a generic header field in the message.
-
Integer SetSender(
String sender )
- Sets the sender of the email.
-
Integer SetSubject(
String subject )
- Set the email subject.
New
MailMessage New()
Returns a new MailMessage object
- Parameters:
-
- Returns:
- A new MailMessage object or undefined if there was an error constructing the object.
AddContent
Integer AddContent(
String content,
Integer contentTransferEncodingType )
Adds inline content to a multipart email message.
- Parameters:
-
content |
- |
the content to inline |
contentTransferEncodingType |
- |
the content transfer encoding type, see above for constants |
- Returns:
- Returns 0 for success and -1 if an error occurred.
AddFileAttachment
Integer AddFileAttachment(
String attachmentName,
String filename,
Integer contentTransferEncodingType,
[String mimeType])
Same as calling AddFilePart ( attachmentName, filename, CONTENT_ATTACHMENT, contentTransferEncodingType ). mimeType param is optional and defaults to 'text/plain'.
- Parameters:
-
attachmentName |
- |
the name for the attachment |
filename |
- |
the filename of the attachment |
contentTransferEncodingType |
- |
the content encoding |
mimeType |
- |
the content mimeType |
- Returns:
- Returns 0 for success and -1 if an error occurred.
AddFilePart
Integer AddFilePart(
String partName,
String fileName,
Integer contentDisposition,
Integer contentEncoding,
[String mimeType])
Adds parts to a multipart email, from a file. Content disposition constants are CONTENT_INLINE or CONTENT_ATTACHMENT. See above for content type encodings. The mimeType string is optional and defaults to "text/plain".
- Parameters:
-
partName |
- |
the name for the part |
fileName |
- |
the filename to use for the part data |
contentDisposition |
- |
the content disposition type |
contentEncoding |
- |
the content encoding |
mimeType |
- |
the content mimeType |
- Returns:
- Returns 0 for success and -1 if an error occurred.
AddRecipient
Integer AddRecipient(
Integer type,
String emailAddress,
[String fullName] )
The type can be one of PRIMARY_RECIPIENT, CC_RECIPIENT or BCC_RECIPIENT. The email param should be the fully qualified email address and the fullName parameter is optional and can contain the users full name ie, "John Doe". You can add as many recipients as you like.
- Parameters:
-
type |
- |
type can be one of PRIMARY_RECIPIENT, CC_RECIPIENT or BCC_RECIPIENT |
emailAddress |
- |
fully qualified email address of the recipient |
fullName |
- |
optional, can be the full name of the user |
- Returns:
- Returns 0 for success and -1 if an error occurred.
AddStringAttachment
Integer AddStringAttachment(
String attachmentName,
String stringData,
Integer contentTransferEncodingType,
[String mimeType])
Same as calling AddStringPart ( attachmentName, stringData, CONTENT_INLINE, contentTransferEncodingType ). mimeType param is optional and defaults to 'text/plain'.
- Parameters:
-
attachmentName |
- |
the name for the attachment |
stringData |
- |
the string data of the attachment |
contentTransferEncodingType |
- |
the content encoding |
mimeType |
- |
the content mimeType |
- Returns:
- Returns 0 for success and -1 if an error occurred.
AddStringPart
Integer AddStringPart(
String partName,
String stringData,
Integer contentDisposition,
Integer contentEncoding,
[String mimeType])
Adds parts to a multipart email, from a text source. See above for content disposition constants. See above for content type encodings. The mimeType string is optional and defaults to "text/plain".
- Parameters:
-
partName |
- |
the name for the part |
stringData |
- |
the string data to use for the part data |
contentDisposition |
- |
the content disposition type |
contentEncoding |
- |
the content encoding |
mimeType |
- |
the content mimeType |
- Returns:
- Returns 0 for success and -1 if an error occurred.
GetContent
String GetContent()
Returns a string containing the content, or body, of the email. No parameters. Only applicable for non-multipart messages.
- Parameters:
-
- Returns:
- Returns a string containing the content, or body, of the email.
GetContentType
String GetContentType()
Gets the content type of the email.
- Parameters:
-
- Returns:
- Returns the content type of the email.
GetDate
String GetDate()
Gets the date of the email.
- Parameters:
-
- Returns:
- Returns the date of the email.
GetHeaderField
String GetHeaderField(
String fieldName)
Gets the data of the specified header field. If the message doesn't contain the fieldname, then the string is empty.
- Parameters:
-
fieldName |
- |
the name of the field to retrieve |
- Returns:
- Returns the data of the field. If the message doesn't contain the fieldname, then the string is empty.
GetHeaders
List GetHeaders()
Returns a List of all the message headers. The list will be undefined if an error occurred.
- Parameters:
-
- Returns:
- Returns a List of all the message headers. The list will be undefined if an error occurred.
GetLastError
String GetLastError( )
No parameters. Returns an error string for the last error that occured.
- Parameters:
-
- Returns:
- Returns an error string for the last error that occured.
GetMultipartContent
RecArray GetMultipartContent()
Returns a RecArray of all of the parts in the email. The format is as follows:
Column 1 : String : name=Type
Column 2 : String : name=Disposition
Column 3 : String : name=Data
Column 4 : String : name=Transfer-Encoding
Column 5 : String : name=Description
Column 6 : String : name=ID
- Parameters:
-
- Returns:
- Returns a RecArray of all of the parts in the email.
GetRawMessage
String GetRawMessage()
Returns a String containing the entire raw contents of the email.
- Parameters:
-
- Returns:
- Returns a String containing the entire raw contents of the email.
GetRecipients
RecArray GetRecipients()
Returns a recArray of the current email recipients with the following record structure:
Column 1 : Integer : name=Type
Column 2 : String : name=Address
Column 3 : String : name=RealName
See above for type constants
- Parameters:
-
- Returns:
- Returns a recArray of the current email recipients.
GetSender
String GetSender()
Gets the sender of the email.
- Parameters:
-
- Returns:
- Returns the sender of the email.
GetSubject
String GetSubject()
Gets the subject of the email.
- Parameters:
-
- Returns:
- Returns the subject of the email.
IsMultipart
Boolean IsMultipart()
TRUE if the email is a multi-part email, FALSE otherwise. No parameters.
- Parameters:
-
- Returns:
- Returns TRUE if the email is a multi-part email, FALSE otherwise.
SetContent
Integer SetContent(
String content,
[Integer contentEncoding] )
Adds text to the body of the email. This function is only for simple non-multipart messages.
- Parameters:
-
content |
- |
the content to add to the body |
contentEncoding |
- |
optional, the contentEncoding type to use to encode the content with, see constants above. The default is ENCODING_QUOTEDPRINTABLE. |
- Returns:
- Returns 0 for success and -1 if an error occurred.
SetContentType
Integer SetContentType(
String mediaType )
Sets the content type of the email.
- Parameters:
-
mediaType |
- |
Sets the content type of the email, default is "text/plain". |
- Returns:
- Returns 0 for success and -1 if an error occurred.
SetDate
Integer SetDate(
Date date )
Sets the date of the email.
- Parameters:
-
date |
- |
the date of the email. |
- Returns:
- Returns 0 for success and -1 if an error occurred.
SetHeaderField
Integer SetHeaderField(
String fieldName,
String fieldData )
Sets a generic header field in the message.
- Parameters:
-
fieldName |
- |
the name of the field to set |
fieldData |
- |
the date for the field |
- Returns:
- Returns 0 for success and -1 if an error occurred.
SetSender
Integer SetSender(
String sender )
Sets the sender of the email.
- Parameters:
-
sender |
- |
the sender of the email. |
- Returns:
- Returns 0 for success and -1 if an error occurred.
SetSubject
Integer SetSubject(
String subject )
Sets the subject of the email.
- Parameters:
-
subject |
- |
the subject of the email. |
- Returns:
- Returns 0 for success and -1 if an error occurred.