SendMessage Method  
 

Send an email message to one or more recipients.

Syntax

object.SendMessage( [Sender], [Recipient], [Message], [Options] )

Parameters

Sender
 An optional string value that identifies the sender of the message and must be a standard Internet email address. If this argument is omitted, then the address specified by the From property will be used.
Recipient
An optional string value that specifies one or more recipients of the message. If this argument is omitted, then the addresses listed in the Bcc, Cc and To properties will be combined to determine the recipients of the message.
Message
An optional string value that contains a complete email message. This must be a formatted message that conforms to the MIME standard for email. If this argument is omitted, then the current message specified by the Message property is sent.
Options
An optional integer value that specifies one or more options for sending the message. If this argument is omitted, the value of the Options property will be used instead. One or more of the following values may be used:
Value Description
mailOptionSecureImplicit This option specifies that an implicit TLS session should be established with the mail server and prevents the use of a command which is used to negotiate an explicit TLS connection.
mailOptionAuthLogin Specifies that the user must be authenticated to the mail server before the message is delivered. This option should only be used if a relay server supports AUTH LOGIN and requires authentication.
mailOptionNotify Notify the sender of the delivery status of the message, if the server supports delivery status notification. This option is a combination of the mailNotifySuccess, mailNotifyFailure, mailNotifyDelay and mailReturnHeaders options.
mailNotifySuccess If the mail server supports delivery status notification, this causes a message to be returned to the sender once it has been successfully delivered.
mailNotifyFailure If the mail server supports delivery status notification, this causes a message to be returned to the sender if it could not be delivered.
mailNotifyDelay If the mail server supports delivery status notification, this causes a message to be returned to the sender if delivery has been delayed.
mailReturnHeaders If the mail server supports delivery status notification, this causes a message to be returned which contains the headers of the message that was sent.
mailReturnMessage If the mail server supports delivery status notification, this causes a message to be returned which contains the complete message that was sent.

Return Value

A value of zero is returned if the method succeeds. Otherwise, a non-zero error code is returned which indicates the cause of the failure.

Remarks

The SendMessage method sends an email message to one or more recipients using the Simple Mail Transfer Protocol (SMTP). The method can be used in several ways, depending on the arguments specified by the caller. If an argument is omitted, the corresponding properties of the control are used to determine the message content, sender and recipients.

If the Message parameter is specified, but the sender and recipient addresses are not explicitly provided, the message is parsed and the addresses are determined from the From, Cc and To header fields. Specifying the Message argument does not change the current value of the Message property.

For most applications, it is recommended that messages be submitted through an SMTP relay server provided by the user's email service or organization. The RelayServer and RelayPort properties specify the server and port used for message submission. Port 587 is commonly used for message submission with explicit TLS negotiation using STARTTLS, while port 465 is commonly used for implicit TLS connections. The Secure property and related options control the use of TLS when connecting to the relay server.

SMTP relay servers typically require the client to authenticate before accepting messages for delivery. Traditional authentication uses the UserName and Password properties with the mailOptionAuthLogin option. For servers that support OAuth 2.0, the application can specify an access token using the BearerToken property. By default, the control uses the XOAUTH2 authentication mechanism when a bearer token is provided. The application is responsible for obtaining a valid access token from the mail service and refreshing it when necessary. Authentication credentials and bearer tokens should only be transmitted over a secure TLS connection.

Most SMTP servers require a secure TLS connection before allowing a client to authenticate. Servers that support explicit TLS using STARTTLS may refuse authentication commands until the secure connection has been established, while servers configured for implicit TLS require the secure connection to be established immediately upon connecting. Applications should enable the Secure property and configure the appropriate connection options for the relay server. Attempting to authenticate over an unencrypted connection may result in the server rejecting the authentication command or immediately terminating the connection without returning an error. This behavior is commonly encountered with servers that enforce strict security policies.

If a relay server is not specified, the control attempts to deliver messages directly to each recipient's mail server by determining the appropriate mail exchange (MX) host. This typically involves connecting to the destination server using SMTP port 25. Although direct delivery is supported for compatibility with existing applications, it is generally not recommended for client applications. Many networks and Internet service providers restrict outbound connections on port 25, and receiving mail servers may reject messages originating from residential networks or systems without appropriate DNS records, sender authentication policies and an established sending reputation.

Using an authenticated relay server avoids many of the problems associated with direct delivery and allows the mail service to handle message routing and delivery. Note that the Secure property and authentication options only apply when a relay server is configured. When delivering messages directly to recipient mail servers, these options are not used.

See Also