- Log on to the DirectMail console.
- On the left-side navigation pane, click Sender Addresses.
- Find the sender address you want to enable SMTP sending feature for and click Set SMTP Password.
- Enter a password, and then click OK.
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.
The latest SMTP RFC is RFC5321.
Two types of email servers use SMTP:
- smtpd: It needs sender authorization.
- mx: It receives emails from outside operator users and delivers them to local users.
Alibaba Cloud DirectMail server uses smtpd, therefore, user authorization is required (the user must be authorized for the sender address). You can authorize users (senders) and set a password for them 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:
- The client uses the telnet command to connect to the SMTP server to create a session.
- The client sends HELO or EHLO command.
- The client sends the AUTH authorization command to log on.
- The client sends MAIL command to specify a sender.
- The client sends RCPT command to specify a recipient.
- The client sends DATA command to enter mail body.
- The client sends . (dot) command to end the command DATA.
- The client sends QUIT command to end the session.
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)
S:250-AUTH=PLAIN LOGIN XALIOAUTH
S:250-AUTH PLAIN LOGIN XALIOAUTH
C:dGVzdEB0ZXN0LmNvbQ== Note: base64 encoding of user email@example.com
C:dGVzdA== base64 encoding of password test
S:235 Authentication successful
C:MAIL FROM: <firstname.lastname@example.org> Note: Sender is enclosed in <> brackets
S:250 Mail Ok
C:RCPT TO: <email@example.com>
S:250 Rcpt Ok
S:354 End data with <CR><LF>.<CR><LF>
S:Data Ok: queued as freedom ###envid=148316944
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 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?