mailReadMessage

Description

Opens a mail message whose ID is stored in the mail session’s message array. You can choose to read the entire message or the envelope (sender, date received, and so on) only. If a message has attachments, they are stored in a temporary file. You can also choose to have the message text written to in a temporary file.

Applies to

mailSession object

Syntax

mailsession.mailReadMessage ( messageid, mailmessage, readoption, 
  mark )

Argument

Description

mailsession

A mailSession object identifying the session in which you want to read a message.

messageid

A string whose value is the ID of the mail message you want to read.

mailmessage

A mailMessage structure in which mailReadMessage stores the message information.

readoption

A value of the mailReadOption enumerated datatype:

  • mailEntireMessage! – Obtain header, text, and attachments

  • mailEnvelopeOnly! – Obtain header information only

  • mailBodyAsFile! – Obtain header, text, and attachments, and treat the message text as the first attachment, storing it in a temporary file

  • mailSuppressAttachments! – Obtain header and text, but no attachments

mark

A boolean indicating whether you want to mark the message as read in the user’s inbox. Values are:

  • TRUE – Mark the message as read

  • FALSE – Do not mark the message as read

Returns

MailReturnCode. Returns one of the following values:

If any argument’s value is null, mailReadMessage returns null.

Usage

To obtain the message IDs for the messages in the user’s inbox, call mailGetMessages.

Before calling mail functions, you must declare and create a mailSession object and call mailLogon to establish a mail session.

NoteReading attachments If a message has an attachment and you do not suppress attachments, information about it is stored in the AttachmentFile property of the mailMessage object. The AttachmentFile property is a mailFileDescription object. Its PathName property has the location of the temporary file that mailReadMessage created for the attachment. By default, the temporary file is in the directory specified by the TEMP environment variable.

Be sure to delete this temporary file when you no longer need it.

Examples

Example 1

In this example, mail is displayed in a window with a DataWindow dw_inbox that lists mail messages and a MultiLineEdit mle_note that displays the message text. Assuming that the application has created the mailSession object mSes and successfully logged on, and that dw_inbox contains a list of mail items (sender, subject, postmark, and message ID); this script for the Clicked event for dw_inbox displays the text of the selected message in the MultiLineEdit mle_note:

integer nRow, nRet

string sMessageID

string sRet, sName


// Find out what Mail Item was selected

nRow = GetClickedRow()

IF nRow > 0 THEN

    // Get the message ID from the row

    sMessageID = GetItemString(nRow, 'MessageID')


    // Reread the message to obtain entire contents

    // because previously we read only the envelope

    mRet = mSes.mailReadMessage(sMessageID, mMsg &

    mailEntireMessage!, TRUE)


    // Display the text

    mle_note.Text = mMsg.NoteText

END IF

See mailGetMessages for an example that creates a list of mail messages in a DataWindow control, the type of setup that this example expects. See also the mail examples in the Code Examples sample application supplied with PowerBuilder.

See also