All Products
Search
Document Center

Direct Mail:Send emails using SMTP

Last Updated:Oct 31, 2025

Enable SMTP sending

To send emails using the SMTP interface, you must first enable the SMTP sending feature.

  1. Log on to the Direct Mail console.

  2. In the navigation pane on the left, click Sender Addresses.

  3. In the list of sender addresses, find the sender address for which you want to enable SMTP sending. In the Actions column, click Set SMTP Password.

  4. In the dialog box that appears, enter an SMTP password and click OK.

SMTP sending method

The Simple Mail Transfer Protocol (SMTP) is a protocol used to send emails. It uses commands and acknowledgements to transfer messages between a client and a server. The client sends a command and the server returns an acknowledgement. This call-and-response process is controlled by the sender.

For more information about the SMTP protocol specification, see RFC5321.

There are two types of mail servers that use the SMTP protocol:

  • A mail sending server, also known as smtpd, which requires sender authentication.

  • A mail receiving server, also known as mx, which accepts emails delivered from external domains to local users.

The Alibaba Cloud Direct Mail server is an smtpd server and requires user authentication. The authentication username must match the sender address. You can set the username and password in the console.

To send emails from a program using SMTP, use an SMTP library for your programming language. For more information, see SMTP call examples.

The process of sending an email using the SMTP protocol is as follows:

  1. The client uses the `telnet` command to connect to the SMTP server and establish a session.

  2. The client sends a `HELO` or `EHLO` command.

  3. The client sends an `AUTH` command to authenticate the user (using the smtpd method).

  4. The client sends a `MAIL` command to specify the sender.

  5. The client sends an `RCPT` command to specify the recipient.

  6. The client sends a `DATA` command to begin sending the email body.

  7. The client sends a `.` (period) to indicate the end of the email body.

  8. The client sends a `QUIT` command to end the session.

Examples

The following example shows a `telnet` session that demonstrates how to send an email using SMTP commands.

Note: S represents the server, and C represents the client. You can use the Linux command `echo -n Content|base64` to perform Base64 encoding.

Unencrypted method:

$telnet smtpdm.aliyun.com 80
S:220 smtp.aliyun-inc.com MX AliMail Server(127.0.0.1)
C:EHLO test.com
S:250-smtp.aliyun-inc.com
S:250-8BITMIME
S:250-AUTH=PLAIN LOGIN XALIOAUTH
S:250-AUTH PLAIN LOGIN XALIOAUTH
S:250-PIPELINING
S:250 DSN
C:AUTH LOGIN
S:334 dXNlcm5hbWU6
C:YSoqKkBleGFtcGxlLm5ldA==         Note: The Base64 encoding of the username a***@example.net.
S:334 UGFzc3dvcmQ6
C:dGVzdA==                     Note: The Base64 encoding of the user password test.
S:235 Authentication successful
C:MAIL FROM: <a***@example.net>   Note: Enclose the sender address in angle brackets (<>).
S:250 Mail Ok
C:RCPT TO: <a***@example.net>
S:250 Rcpt Ok
C:DATA
S:354 End data with <CR><LF>.<CR><LF>
C:subject: test
C:from: <a***@example.net>
C:to: <a***@example.net>
C:
C:test
C:.
S:Data Ok: queued as freedom ###envid=148316944
C:QUIT
S:221 Bye

Encrypted method (requires the OpenSSL tool):

openssl s_client -connect smtpdm.aliyun.com:465 -crlf
or
openssl s_client -cipher AES128-GCM-SHA256 -connect  smtpdm.aliyun.com:465 -tls1_3 -crlf

After OpenSSL successfully connects, enter the following client commands line-by-line in the same window:

$openssl s_client -connect smtpdm.aliyun.com:465 -crlf
***
***
***
S:220 DirectMail Smtpd Server(127.0.0.1)
C:EHLO test.com
S:250-smtp.aliyun-inc.com
S:250-8BITMIME
S:250-AUTH=PLAIN LOGIN XALIOAUTH
S:250-AUTH PLAIN LOGIN XALIOAUTH
S:250-PIPELINING
S:250 DSN
C:AUTH LOGIN
S:334 dXNlcm5hbWU6
C:YSoqKkBleGFtcGxlLm5ldA==          Note: The Base64 encoding of the username a***@example.net.
S:334 UGFzc3dvcmQ6
C:dGVzdA==                        Note: The Base64 encoding of the user password test.
S:235 Authentication successful
C:MAIL FROM: <a***@example.net>  Note: Enclose the sender address in angle brackets (<>).
S:250 Mail Ok
C:rcpt to: <a***1@example.net>  Note: Use lowercase for rcpt to. Uppercase may not be recognized.
S:250 Rcpt Ok
C:DATA
S:354 End data with <CR><LF>.<CR><LF>
C:subject: test
C:from: <a***@example.net>
C:to: <a***1@example.net>
C:
C:test
C:.
S:250 Data Ok: queued as freedom ###envid=600000105713504612
C:QUIT
S:DONE

In the example, the email body entered after the `DATA` command is a simple text string. For a standard rich text email, you must format it according to the Multipurpose Internet Mail Extensions (MIME) specification. This includes encoding the subject and body. Proper formatting reduces the risk of the recipient's server identifying the email as spam.

For more information about the MIME protocol, see RFC2045. You can use the language-specific libraries provided in the SMTP sending examples on the official Alibaba Cloud website to encode MIME emails.

For more information about how to build a MIME email, see How do I send an email with an attachment using SMTP?