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:

  • New() Creates a new MailMessage object.
  • AddRecipient() and GetRecipients() to manipulate email recipients.
  • GetHeaders() to return a list of all the message headers.
  • SetSubject() and GetSubject() to manipulate email subject.
  • SetSender() and GetSender() to manipulate email sender.
  • SetContent() and GetContent() to manipulate email contents.
  • SetContentType() and GetContentType() to manipulate email content type.
  • SetDate() and GetDate() to manipulate email date.
  • SetHeaderField() and GetHeaderField() to manipulate email headers.
  • IsMultipart(), GetMultipartContent(), AddFilePart(), AddStringPart(), AddContent(), AddFileAttachment(), AddStringAttachment() to manipulate email multipart content.
  • GetRawMessage() to return a string containing the entire raw message.
  • GetLastError() to return a string for the last error that occured.

  • Class Methods Index

     o MailMessage New ()
    Returns a new MailMessage instance, or undefined if an error occured.

    Function Constants Index

    Email Recipient Types

     o PRIMARY_RECIPIENT
    Used to indicate that the specified recipient is a primary recipient, ie, the To: field
     o CC_RECIPIENT
    Used to indicate that the specified recipient is a CC recipient, ie, the CC: field
     o BCC_RECIPIENT
    Used to indicate that the specified recipient is a BCC recipient, ie, the BCC: field

    Content Type Encoding Constants

     o ENCODING_7BIT
    Specifies 7 bit encoding for the content
     o ENCODING_8BIT
    Specifies 8 bit encoding for the content
     o ENCODING_QUOTEDPRINTABLE
    Specifies quoted printable encoding for the content
     o ENCODING_BASE64
    Specifies base64 encoding for the content

    Content Disposition Type Constants

     o CONTENT_INLINE
    Specifies inline content
     o CONTENT_ATTACHMENT
    Specifies attachment content

    Instance Methods Index

     o Integer AddContent( String content, Integer contentTransferEncodingType )
    Adds inline content to a multipart email message.
     o Integer AddFileAttachment( String attachmentName, String fileName, Integer contentTransferEncodingType, String mimeType )
    Same as calling AddFilePart (attachmentName, filename, CONTENT_ATTACHMENT, contentTransferEncodingType,"text/plain" ) .
     o Integer AddFilePart( String partName, String filename, Integer contentDisposition, Integer contentEncoding, String mimeType )
    Adds data to a multi-part email from a file.
     o Integer AddRecipient( Integer recipientType, String emailAddress, String fullName )
    Add a recipient to an email.
     o Integer AddStringAttachment( String attachmentName, String stringData, Integer contentTransferEncodingType, String mimeType )
    Same as calling AddStringPart (attachmentName, stringData, CONTENT_INLINE, contentTransferEncodingType,"text/plain" ) .
     o Integer AddStringPart( String partName, String stringData, Integer contentDisposition, Integer contentEncoding, String mimeType )
    Adds string data to a multi-part email.
     o String GetContent()
    Retrieves the body of the message.
     o String GetContentType()
    retrieves the email content type.
     o Date GetDate()
    Retrieves the date of the email.
     o String GetHeaderField( String fieldName )
    Retrieves the field data for a specific header field.
     o List GetHeaders()
    Returns a list of all the email message headers.
     o String GetLastError()
    Retrieve the a string for the last error code.
     o List GetMultipartContent()
    Retrieves a list of the multipart content.
     o String GetRawMessage()
    Retrieves the full text of the raw message.
     o RecArray GetRecipients( )
    Returns a RecArray of recipients.
     o String GetSender()
    Retrieves the sender of the email.
     o String GetSubject()
    Returns the subject from the email.
     o Boolean IsMultipart()
    Checks if the message is a multi-part email.
     o Integer SetContent( String content, Integer contentEncoding )
    Adds content to the body of the email.
     o Integer SetContentType( String contentType )
    Set the email content type.
     o Integer SetDate( Date date )
    Sets the date of the email.
     o Integer SetHeaderField( String fieldname, String fieldData )
    Sets a generic header field in the message.
     o Integer SetSender( String sender )
    Sets the sender of the email.
     o Integer SetSubject( String subject )
    Set the email subject.

    Class Methods

     o New
     MailMessage New()
            
    

    Returns a new MailMessage object

    Parameters:
    None
    Returns:
    A new MailMessage object or undefined if there was an error constructing the object.

    Instance Methods

     o 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.
     o 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.
     o 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.
     o 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.
     o 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.
     o 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.
     o GetContent
     String GetContent()
    

    Returns a string containing the content, or body, of the email. No parameters. Only applicable for non-multipart messages.

    Parameters:
    None
    Returns:
    Returns a string containing the content, or body, of the email.
     o GetContentType
     String GetContentType()
    

    Gets the content type of the email.

    Parameters:
    None
    Returns:
    Returns the content type of the email.
     o GetDate
     String GetDate()
    

    Gets the date of the email.

    Parameters:
    None
    Returns:
    Returns the date of the email.
     o 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.
     o GetHeaders
     List GetHeaders()
    

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

    Parameters:
    None
    Returns:
    Returns a List of all the message headers. The list will be undefined if an error occurred.
     o GetLastError
     String GetLastError( )
    

    No parameters. Returns an error string for the last error that occured.

    Parameters:
    None.
    Returns:
    Returns an error string for the last error that occured.
     o 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:
    None
    Returns:
    Returns a RecArray of all of the parts in the email.
     o GetRawMessage
     String GetRawMessage()
    

    Returns a String containing the entire raw contents of the email.

    Parameters:
    None
    Returns:
    Returns a String containing the entire raw contents of the email.
     o 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:
    None
    Returns:
    Returns a recArray of the current email recipients.
     o GetSender
     String GetSender()
    

    Gets the sender of the email.

    Parameters:
    None
    Returns:
    Returns the sender of the email.
     o GetSubject
     String GetSubject()
    

    Gets the subject of the email.

    Parameters:
    None
    Returns:
    Returns the subject of the email.
     o IsMultipart
     Boolean IsMultipart()
    

    TRUE if the email is a multi-part email, FALSE otherwise. No parameters.

    Parameters:
    None
    Returns:
    Returns TRUE if the email is a multi-part email, FALSE otherwise.
     o 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.
     o 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.
     o 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.
     o 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.
     o 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.
     o 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.