SendMail

Send an email message, specifying the header, body, and attachments.

SendMail(SMTPServer,HeaderList,Text,AttList,MailSize)

Parameters

Parameter Type Direction Description
SMTPServer string IN SMTP server that will be used to send email. The port that the SMTP server is listening on can be specified, using the format:

SMTPServer+Port.

If Port is not given, the default port number of 25 is used. The maximum size of this parameter is 1024 bytes.

HeaderList string IN Associated list of header-value pairs. The maximum size of this parameter is 10240 bytes. The header values that can be set are described in the following table.
Text string IN Body of the email. The maximum size of this parameter is 10240000 bytes. Data exceeding 10240000 bytes will be truncated.
AttList string IN List giving the location of any files that should be sent as attachments to the email. The maximum size of this parameter is 10240 bytes.
MailSize numeric IN Maximum size of sent messages. Set MailSize to 0 if no size checking should be done.
SendMail HeaderList Member Pairs
Label Description
TO One or more email addresses of recipients (mandatory)
FROM Email address of sender (mandatory)
CC One or more email addresses of other recipients
BCC Blind email addresses of any other recipients.
SUBJECT Subject line of email message
PRIORITY Priority level of a message (1-5, highest-lowest)
REPLY Reply address to specify an alternate address instead of the address the message was sent from

Note:  The Labels are case-sensitive so uppercase must be used.

Return Values

Values Returned by SendMail in $status
Value Description
0 SendMail succeeded
< 0 SendMail failed
-2 Invalid email address in To or From
-6 Size of message text and attachment(s) exceeds MailSize parameter
-7 SMTP server does not support security driver functionality
-8 Security context could not be established. Either the DriverParameters argument of the SetSecurity operation contained invalid keywords or data, or some protocol error occurred with the SMTP server.
-9 Socket error, or invalid server name
-10 Miscellaneous error
-12 Missing mandatory elements in HeaderList
-13 Attachment file(s) not reachable
-14 Mime encoding failed
-15 Quota on server exceeded

Description

Note:  This operation is available for compatibility with releases prior to 9.4.01. Instead of using SendMail, we recommend that you define the email header, content, and attachments using separate Set operations, and then use the Send operation,

The SendMail operation is used to assemble and send an email message.

SendMail implicitly calls LogonSMTP, and LogoffSMTP if no connection to the SMTP server was explicitly established. SendMail can therefore also return the values LogonSMTP returns. When errors occur, the state of the security context is as described in LogonSMTP.

If you use SendMail repeatedly to send multiple emails, consider using LogonSMTP first to leave the connection open. After you have sent all emails, perform LogoffSMTP to close the connection.

Emails are sent to SMTP servers in UTF-8 format. The complete content, including subject and message body, are encoded as UTF-8 before being further encoded as Base64 for network transport. The character set is specified in the message header, so upon arrival, the SMTP server automatically decodes the Base64 message into UTF-8.

Sending an Email

The following example shows how to send the contents of the field MAIL_MESSAGE to user doctor.gonzo@blah.blah.net, with a subject line of "Conference Registration". The SMTP server is called mailhost.wangle.com.

$$header = "TO=doctor.gonzo@my.net;FROM=%%$user%%%@shrubco.com;SUBJECT=Conference Registration"
activate "UPOPMail".SendMail("mailhost.wangle.com", $$header, MAIL_MESSAGE, "",0)

Related Topics