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.