Skip to main content

Using Email Messages

Using Email Messages

As noted earlier, after you retrieve an email message (%Net.MailMessageOpens in a new tab), you generally start by determining what kind of message it is and how to read it; that is, whether it is a multipart message and whether the parts are binary.

In this step, you can use the ContentType property, which is equivalent to the Content-Type property. Or you can use the IsBinary, IsHTML, and IsMultiPart properties, which indirectly provide the same information as ContentType.

If the message is a multipart message, each part is an instance of %Net.MailMessagePartOpens in a new tab.

A message has message headers; each part of the message can also have message headers. You can access the headers via various properties of %Net.MailMessageOpens in a new tab and %Net.MailMessagePartOpens in a new tab.

Message Contents

Once you know what the general message structure is, use the following techniques to retrieve the contents:

  • For a multipart message, use the Parts property, which is an array of the parts. Use the Count() method to get the number of parts. Use the GetAt() method to retrieve a given part; the key for each part is an integer, starting with 1 for the first part.

  • For a binary message (or message part), use the BinaryData property.

  • For a text message (or message part), use the TextData property.

    • If IsHTML is 0, the TextData property is an ordinary text string.

    • If IsHTML is 1, the TextData property is an HTML text string.

Note that the email client that sends a message determines any wrapping in the message. The mail server has no control over this; nor does InterSystems IRIS.

Message Headers

The message itself and each part of the message has a set of headers.

The %Net.MailMessageOpens in a new tab class provides properties that give you the most commonly used headers.

  • To — The list of email addresses to which this message was sent. This property is a standard InterSystems IRIS list; to work with it, you use the standard list methods: Insert(), GetAt(), RemoveAt(), Count(), and Clear().

  • From — The email address from which this message was sent.

  • Date — The date of this message.

  • Subject — A string containing the subject for this message.

  • Sender — The actual sender of the message.

  • Cc — The list of carbon copy addresses to which this message was sent.

  • Bcc — The list of blind carbon copy addresses to which this message was sent. If the receiver of the message was on the blind carbon copy list, this property contains the address of the receiver; otherwise, it is null.

Both %Net.MailMessageOpens in a new tab and %Net.MailMessagePartOpens in a new tab provide the following properties, which give you other headers:

  • ContentType — The Content-Type header of the message or message part.

  • ContentTransferEncoding — The Content-Transfer-Encoding header of the message or message part.

  • Headers — A multidimensional array that gives access to any additional headers.

Also, you can use the GetAttribute() method. Given a header name and an attribute, this method returns the value of that attribute.

Other Message Information

The following properties and methods provide additional information about the message:

  • The MessageSize property indicates the total length of the message, apart from any attached email messages.

  • The GetLocalDateTime() method returns the date and time when the message was retrieved, converted to local time in $HOROLOG format.

  • The GetUTCDateTime() method returns the date and time when the message was retrieved, converted to UTC in $HOROLOG format.

  • The GetUTCSeconds() method returns the date and time when the message was retrieved, in seconds since 12/31/1840.

  • The HToSeconds() class method converts a date/time in $HOROLOG format to seconds since 12/31/1840.

  • The SecondsToH() class method converts seconds since 12/31/1840 to a date/time in $HOROLOG format.

FeedbackOpens in a new tab