mailSaveMessage PowerScript function
Description
Creates a new message in the user’s inbox or replaces
an existing message.
Controls
mailSession object
Syntax
1 |
<span>mailsession</span>.<span>mailSaveMessage</span> ( <span>messageid</span>, <span>mailmessage</span> ) |
Argument |
Description |
---|---|
mailsession |
A mailSession object identifying the |
messageid |
A string whose value is the message ID |
mailmessage |
A mailMessage structure containing the |
Return Values
mailReturnCode. Returns one of the following values:
-
mailReturnSuccess!
-
mailReturnFailure!
-
mailReturnInsufficientMemory!
-
mailReturnInvalidMessage!
-
mailReturnUserAbort!
-
mailReturnDiskFull!
If any argument’s value is null, mailSaveMessage returns null.
Usage
Before saving a message, you must address the message even
if you are replacing an existing message. The message can be addressed
to someone else for sending later.
Before calling mail functions, you must declare and create
a mailSession object and call mailLogon to establish
a mail session.
Examples
This example creates a new message in the inbox of
the current user, which will be sent later to Jerry Smith. The application
has already created the mailSession object mSes and
logged on:
1 |
mailRecipient recip |
1 |
mailMessage msg |
1 |
mailReturnCode mRet |
1 |
1 |
recip.Name = "Smith, Jerry" |
1 |
mRet = mSes.mailResolveRecipient(recip) |
1 |
IF mRet <> mailReturnSuccess! THEN |
1 |
MessageBox("Save New Message", & |
1 |
"Invalid address.") |
1 |
RETURN |
1 |
END IF |
1 |
1 |
msg.NoteText = mle_note.Text |
1 |
msg.Subject = sle_subject.Text |
1 |
msg.Recipient[1] = recip |
1 |
1 |
mRet = mSes.<span>mailSaveMessage</span>("", msg) |
1 |
IF mRet <> mailReturnSuccess! THEN |
1 |
MessageBox("Save New Message", & |
1 |
"Failed somehow.") |
1 |
END IF |
This example replaces the last message in the user
Jane Smith’s inbox. It gets the message ID from the MessageID
array in the mailSession object mSes. It changes
the message subject, re-addresses the message to the user, and saves the
message. The application has already created the mailSession object mSes and
logged on:
1 |
mailRecipient recip |
1 |
mailMessage msg |
1 |
mailReturnCode mRet |
1 |
string s_ID |
1 |
1 |
mRet = mSes.mailGetMessages() |
1 |
IF mRet <> mailReturnSuccess! THEN |
1 |
MessageBox("No Messages", "Inbox empty.") |
1 |
RETURN |
1 |
END IF |
1 |
s_ID = mSes.MessageID[UpperBound(mSes.MessageID)] |
1 |
mRet = mSes.mailReadMessage(s, msg, & |
1 |
mailEntireMessage!, FALSE ) |
1 |
IF mRet <> mailReturnSuccess! THEN |
1 |
MessageBox("Message", "Can't read message.") |
1 |
RETURN |
1 |
END IF |
1 |
1 |
msg.Subject = msg.Subject + " Test" |
1 |
recip.Name = "Smith, Jane" |
1 |
mRet = mSes.mailResolveRecipient( recip ) |
1 |
msg.Recipient[1] = recip |
1 |
mRet = mSes.<span>mailSaveMessage</span>(s_ID, msg) |
1 |
IF mRet <> mailReturnSuccess! THEN |
1 |
MessageBox("Save Old Message", "Failed somehow.") |
1 |
END IF |
See also the mail examples in the samples that are supplied
with PowerBuilder.