OScript API/Built-in Package Index

Class: MailMessage

The built-in functions in the MailMessage class provide the ability to create and read e-mail messages for SMTP or POP3 sessions.

The MailMessage class offers the following functionality:

Class Attributes

Add a recipient as a blind-carbon-copy (BCC) recipient of an e-mail message.

Add a recipient as a carbon-copy (CC) recipient of an e-mail message.

Set the Content-Disposition for a message part to 'attachment'.

Set the Content-Disposition for a message part to 'inline'.

Set the message Content-Transfer-Encoding to '7-bit'.

Set the message Content-Transfer-Encoding to '8-bit'.

Set the message Content-Transfer-Encoding to 'base64'.

Set the message Content-Transfer-Encoding to 'quoted-printable'.

Add a recipient as the primary recipient of an e-mail message.

Class Methods

New( )

Returns a new, empty MailMessage object.

Instance Methods

AddContent( String content, Integer contentEncoding )

Adds inline content to a multipart e-mail message.

AddFileAttachment( String attachmentName, String filename, Integer contentEncoding, [String contentType] )

Same as calling AddFilePart( attachmentName, filename, CONTENT_ATTACHMENT, contentEncoding, contentType ).

AddFilePart( String partName, String fileName, Integer contentDisposition, Integer contentEncoding, [String contentType] )

Adds a part from a file to a multipart e-mail.

AddImagePart( String partName, String fileName, String contentID, Integer contentDisposition, Integer contentEncoding, [String contentType] )

Adds an image part to a multipart message.

AddRecipient( Integer type, String emailAddress, [String fullName] )

Add a recipient to an e-mail.

AddStringAttachment( String attachmentName, String stringData, Integer contentEncoding, [String contentType] )

Same as calling AddStringPart( attachmentName, stringData, CONTENT_ATTACHMENT, contentEncoding, contentType ) .

AddStringPart( String partName, String stringData, Integer contentDisposition, Integer contentEncoding, [String contentType] )

Adds string data to a multipart e-mail.

Retrieves a list of the multipart content.

Retrieves the body of the message.

Retrieves the e-mail content type.

Retrieves the date of the e-mail.

Returns the set of all the e-mail message headers.

GetHeaderField( String fieldName )

Retrieves the field data for a specific header field.

Returns a list of all the e-mail message headers.

Retrieve the a string for the last error code.

Retrieves a table of the multipart content.

Retrieves the full text of the raw message.

Returns a RecArray of recipients.

Retrieves the sender of the e-mail.

Returns the subject of the e-mail.

Checks if the message is a multipart e-mail.

Processes the MailMessage data and returns an Assoc.

SetContent( String content, [Integer contentEncoding] )

Adds content to the body of the e-mail.

SetContentType( String contentType )

Set the e-mail content type.

SetDate( Date date )

Sets the origination date of the e-mail.

SetHeaderField( String fieldName, String fieldValue )

Sets a generic header field in the message.

SetRawMessage( String rawMessage )

Reads a String representation of an e-mail message.

SetSender( String sender )

Sets the sender of the e-mail.

SetSubject( String subject )

Sets the subject of the e-mail.

Class Attributes

Integer BCC_RECIPIENT

Add a recipient as a blind-carbon-copy (BCC) recipient of an e-mail message.

Integer CC_RECIPIENT

Add a recipient as a carbon-copy (CC) recipient of an e-mail message.

Set the Content-Disposition for a message part to 'attachment'.

Set the Content-Disposition for a message part to 'inline'.

Integer ENCODING_7BIT

Set the message Content-Transfer-Encoding to '7-bit'.

Integer ENCODING_8BIT

Set the message Content-Transfer-Encoding to '8-bit'.

Set the message Content-Transfer-Encoding to 'base64'.

Set the message Content-Transfer-Encoding to 'quoted-printable'.

Add a recipient as the primary recipient of an e-mail message.

Class Methods

New

MailMessage New()

Returns a new, empty MailMessage object.

Returns:

A new MailMessage object or Undefined if there was an error constructing the object.

Instance Methods

AddContent

Integer AddContent( String content,
                    Integer contentEncoding )

Adds inline content to a multipart e-mail message.

Parameters

content

the content to inline

contentEncoding

the content transfer encoding type: ENCODING_7BIT, ENCODING_8BIT, ENCODING_QUOTEDPRINTABLE, or ENCODING_BASE64

Returns:

Returns 0 for success and -1 if an error occurred.

AddFileAttachment

Integer AddFileAttachment( String attachmentName,
                           String filename,
                           Integer contentEncoding,
                           [String contentType] )

Same as calling AddFilePart( attachmentName, filename, CONTENT_ATTACHMENT, contentEncoding, contentType ).

If the contentType is not specified, then it will be assumed to be "application/octet-stream".

Parameters

attachmentName

the name of the attachment

filename

the filename of the attachment

contentEncoding

the content transfer encoding type: ENCODING_7BIT, ENCODING_8BIT, ENCODING_QUOTEDPRINTABLE, or ENCODING_BASE64

contentType

the content type of the attachment

Returns:

Returns 0 for success and -1 if an error occurred.

AddFilePart

Integer AddFilePart( String partName,
                     String fileName,
                     Integer contentDisposition,
                     Integer contentEncoding,
                     [String contentType] )

Adds a part from a file to a multipart e-mail.

If the contentType is not specified, then it will be assumed to be "application/octet-stream".

Parameters

partName

the name for the part

fileName

the filename to use for the part data

contentDisposition

the content disposition type: CONTENT_ATTACHMENT or CONTENT_INLINE

contentEncoding

the content transfer encoding type: ENCODING_7BIT, ENCODING_8BIT, ENCODING_QUOTEDPRINTABLE, or ENCODING_BASE64

contentType

the content type of the message part

Returns:

Returns 0 for success and -1 if an error occurred.

AddImagePart

Integer AddImagePart( String partName,
                      String fileName,
                      String contentID,
                      Integer contentDisposition,
                      Integer contentEncoding,
                      [String contentType] )

Adds an image part to a multipart message. The image is included via Content-ID in an HTML body part.

Parameters

partName

the name for the part

fileName

the filename to use for the image

contentID

the content ID that corresponds to an image embedded in the HTML content

contentDisposition

the content disposition type: CONTENT_ATTACHMENT or CONTENT_INLINE

contentEncoding

the content transfer encoding type: ENCODING_7BIT, ENCODING_8BIT, ENCODING_QUOTEDPRINTABLE, or ENCODING_BASE64

contentType

the content type of the image part

Returns:

Returns 0 for success and -1 if an error occurred.

Example

// Create a new mail message
MailMessage m = MailMessage.New()

// To: John W. Doe <john.doe@example.com>
m.AddRecipient( 
    MailMessage.PRIMARY_RECIPIENT, 
    "john.doe@example.com", 
    "John W. Doe" )

// Cc: Jane Doe <jane.doe@example.com>
m.AddRecipient( 
    MailMessage.CC_RECIPIENT, 
    "jane.doe@example.com", 
    "Jane Doe" )

// Add the HTML body which includes the image
m.AddStringPart( 
    'body', 
    'Example body <img src="cid:example_image">', 
    MAILMESSAGE.CONTENT_INLINE, 
    MAILMESSAGE.ENCODING_BASE64, 
    'text/html' )

// Add the image from a file
m.AddImagePart( 
    'image', 
    '/path/to/image.png', 
    'example_image', 
    MAILMESSAGE.CONTENT_INLINE, 
    MAILMESSAGE.ENCODING_BASE64, 
    'image/png' )

AddRecipient

Integer AddRecipient( Integer type,
                      String emailAddress,
                      [String fullName] )

The type can be one of PRIMARY_RECIPIENT, CC_RECIPIENT or BCC_RECIPIENT.

The e-mail parameter should be the fully qualified e-mail address and the fullName parameter is optional and can contain the user's full name (e.g. "John Doe").

Parameters

emailAddress

fully qualified e-mail address of the recipient

fullName

the full name of the recipient

Returns:

Returns 0 for success and -1 if an error occurred.

Example

// Create a new mail message
MailMessage m = MailMessage.New()

// To: John W. Doe <john.doe@example.com>
m.AddRecipient( MailMessage.PRIMARY_RECIPIENT, "john.doe@example.com", "John W. Doe" )

// Cc: Jane Doe <jane.doe@example.com>
m.AddRecipient( MailMessage.CC_RECIPIENT, "jane.doe@example.com", "Jane Doe" )

AddStringAttachment

Integer AddStringAttachment( String attachmentName,
                             String stringData,
                             Integer contentEncoding,
                             [String contentType] )

Same as calling AddStringPart( attachmentName, stringData, CONTENT_ATTACHMENT, contentEncoding, contentType ).

If the contentType is not specified, then it will be assumed to be "text/plain; charset=UTF-8".

Parameters

attachmentName

the name for the attachment

stringData

the string data of the attachment

contentEncoding

the content transfer encoding type: ENCODING_7BIT, ENCODING_8BIT, ENCODING_QUOTEDPRINTABLE, or ENCODING_BASE64

contentType

the content type of the message part

Returns:

Returns 0 for success and -1 if an error occurred.

AddStringPart

Integer AddStringPart( String partName,
                       String stringData,
                       Integer contentDisposition,
                       Integer contentEncoding,
                       [String contentType] )

Adds parts to a multipart e-mail, from a text source.

If the contentType is not specified, then it will be assumed to be "text/plain; charset=UTF-8".

Parameters

partName

the name for the part

stringData

the string data to use for the part data

contentDisposition

the content disposition type: CONTENT_ATTACHMENT or CONTENT_INLINE

contentEncoding

the content transfer encoding type: ENCODING_7BIT, ENCODING_8BIT, ENCODING_QUOTEDPRINTABLE, or ENCODING_BASE64

contentType

the content type of the message part

Returns:

Returns 0 for success and -1 if an error occurred.

GetAllMultipartContent

RecArray GetAllMultipartContent()

Returns a List of all the parts in a multipart message. Each part is an Assoc which contains the following keys:

  • header: An Assoc which contains the part headers (e.g. Content-Type, Content-Disposition, etc.)
  • parts: If the part is a container for other parts, then this is a list of parts
  • multipartSubType: If the part is a container for other parts, then this is the second part of its content type (e.g. "multipart/mixed" becomes "mixed")
  • body: If the part is not a container for other parts, this is the raw content of the part

Returns:

Returns a RecArray of all of the parts in the e-mail.

GetContent

String GetContent()

Returns a string containing the content, or body, of the e-mail. This is only applicable for single-part messages.

Returns:

Returns a string containing the content, or body, of the e-mail.

GetContentType

String GetContentType()

Retrieves the e-mail content type.

Returns:

the content type of the e-mail.

GetDate

Date GetDate()

Gets the date of the e-mail.

Returns:

The origination date of the e-mail, adjusted to UTC.

GetHeaderAssoc

Assoc GetHeaderAssoc()

Returns the set all the message headers as an Assoc. The Assoc will be Undefined if an error occurred.

Returns:

Returns the set of all the message headers as an Assoc. The Assoc will be Undefined if an error occurred.

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:

The data of the field, or an empty String if the header field does not exist.

GetHeaders

List GetHeaders()

Returns a List of all the message headers. The list will be Undefined if an error occurred.

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 occurred.

Returns:

Returns an error string for the last error that occurred.

GetMultipartContent

RecArray GetMultipartContent()

Returns a RecArray of all top-level parts in a multipart message. The following fields will be returned for each part:

  • type: the content type
  • disposition: the content disposition
  • data: the raw contents of the part
  • encoding: the content transfer encoding
  • description: description of the part
  • id: part identifier

Returns:

Returns a RecArray of all of the parts in the e-mail.

GetRawMessage

String GetRawMessage()

Returns a String containing the entire raw contents of the e-mail.

Returns:

Returns a String containing the entire raw contents of the e-mail.

GetRecipients

RecArray GetRecipients()

Returns a RecArray of the current e-mail recipients. Each recipient record consists of the following data:

  • type: one of PRIMARY_RECIPIENT, CC_RECIPIENT, or BCC_RECIPIENT
  • address: the recipient's e-mail address
  • realName: the recipient's real name, if available

Returns:

Returns a RecArray of the current e-mail recipients.

GetSender

String GetSender()

Gets the sender of the e-mail.

Returns:

Returns the sender of the e-mail.

GetSubject

String GetSubject()

Gets the subject of the e-mail.

Returns:

Returns the subject of the e-mail.

IsMultipart

Boolean IsMultipart()

TRUE if the e-mail is a multipart e-mail, FALSE otherwise. No parameters.

Returns:

Returns TRUE if the e-mail is a multipart e-mail, FALSE otherwise.

ProcessMessage

Assoc ProcessMessage()

Processes the MailMessage data and returns an Assoc. The Assoc has the following keys:

  • header: message header as returned by GetHeaders()
  • parts: if this is a multipart message, then a list of parts, as returned by GetAllMultipartContent()
  • multipartSubType: if the part is a container for other parts, then this is the second part of its content type (e.g. "multipart/mixed" becomes "mixed")
  • body: if this message is a single-part message, then this is the raw content of the part

Returns:

The processed MailMessage data

SetContent

Integer SetContent( String content,
                    [Integer contentEncoding] )

Adds text to the body of the e-mail. This function is only for single-part messages.

Parameters

content

the content to add to the body

contentEncoding

the content transfer encoding type: ENCODING_7BIT, ENCODING_8BIT, ENCODING_QUOTEDPRINTABLE, or ENCODING_BASE64

Returns:

Returns 0 for success and -1 if an error occurred.

SetContentType

Integer SetContentType( String contentType )

Sets the content type of the e-mail.

Parameters

contentType

Sets the content type of the e-mail.

Returns:

Returns 0 for success and -1 if an error occurred.

SetDate

Integer SetDate( Date date )

Sets the origination date of the e-mail.

Parameters

date

the origination date of the e-mail

Returns:

Returns 0 for success and -1 if an error occurred.

SetHeaderField

Integer SetHeaderField( String fieldName,
                        String fieldValue )

Sets a generic header field in the message.

Parameters

fieldName

the name of the field to set

fieldValue

the String representation of the value for the field

Returns:

Returns 0 for success and -1 if an error occurred.

SetRawMessage

Integer SetRawMessage( String rawMessage )

Reads a String representation of an e-mail message.

Parameters

rawMessage

a raw message as a String

Returns:

Returns 0 for success and -1 if an error occurred.

SetSender

Integer SetSender( String sender )

Sets the sender of the e-mail.

Parameters

sender

the sender of the e-mail.

Returns:

Returns 0 for success and -1 if an error occurred.

SetSubject

Integer SetSubject( String subject )

Sets the subject of the e-mail.

Parameters

subject

the subject of the e-mail.

Returns:

Returns 0 for success and -1 if an error occurred.

 Copyright © 2022 OpenText Corporation. All rights reserved.