All Products
Search
Document Center

Direct Mail:Send Emails by SMTP

最終更新日:Jan 23, 2024

Enable SMTP Email Sending Feature

  1. Log on to the Direct Mail Console.

  2. On the left-side navigation pane, click Sender Addresses.

  3. Find the sender address you want to enable SMTP sending feature for and click Set SMTP Password.

  4. Enter a password, and then click OK.

SMTP Email Sending Method

SMTP uses commands and responses to transfer messages between clients and servers. A client sends a command, and a server returns a response. The sender and the recipient interact in a question-and-answer session, which is controlled by the sender.

SMTP RFC protocol reference RFC5321.

Two types of email servers use SMTP:

  • SMTP: It needs sender authentication.

  • MX: It receives emails from outside operator users and delivers them to local users.

Alibaba Cloud Direct Mail server uses smtpd, therefore, user authentication is required (the user must be authenticated for the sender address). You can authenticate the user (sender address) and set a password in the DirectMail Console. You can use the SMTP library to call the SMTP sending interface. For more information, see SMTP Reference.

The overall process for sending an email using SMTP is as follows:

  1. The client uses the telnet command to connect to the SMTP server to create a session.

  2. The client sends HELO or EHLO command.

  3. The client sends the AUTH authentication command to log on(Use smtpd mode)

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

  5. The client sends RCPT command to specify a recipient.

  6. The client sends DATA command to enter the mail body.

  7. The client sends . (dot) command to end the command DATA.

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

Example

The following telnet command session is provided to demonstrate an SMTP command session in order for you to familiarize yourself with how to send an email using SMTP.

Note: S stands for server, and C stands for client. Linux echo -n Content|base64 command can be used for base64 encoding.

$telnet smtpdm.aliyun.com 25
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: base64 encoding of user a***@example.net
S:334 UGFzc3dvcmQ6
C:dGVzdA==                     base64 encoding of password test
S:235 Authentication successful
C:MAIL FROM: <a***@example.net>   Note: Sender is enclosed in <> 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

In the preceding example, the email body entered after the command DATA is a simple text string. For standard rich text emails, you must build emails in the MIME format. The emails must contain subjects and bodies to prevent the emails from being tagged as spam.

For MIME protocol, see RFC 2045. You can use the library with multiple programming languages to encode MIME emails. Examples are provided on the Alibaba Cloud official website for different programming languages.

For more information on how to build MIME emails, see How can I send emails with attachments using SMTP?