Send emails from Alibaba Mail using SMTP

更新时间:
复制 MD 格式

This topic describes how to send emails from an Alibaba Mail account using an SMTP program.

Introduction to SMTP

The simple mail transfer protocol (SMTP) is the standard protocol for sending emails. Using an SMTP program, you can automate email sending for tasks such as sending verification codes, notifications, or marketing messages.

Prerequisites

SMTP server and port information

For more information, see Configure IMAP, POP, and SMTP server addresses and ports.

SMTP server address: smtp.qiye.aliyun.com or smtp.[$Domain].

SMTP server port: 25, 80, or 465 (for SSL encryption). By default, port 25 is blocked on ECS instances. We recommend using port 80 or 465 instead.

Note

If you want to use your own domain name, add a CNAME record for SMTP. For instructions on how to configure DNS resolution, see DNS resolution for Alibaba Mail. In this context, [$Domain] represents your domain name.

Alternatively, you can use the official Alibaba Mail server address: smtp.qiye.aliyun.com.

Enable SMTP sending for Alibaba Mail

Enable SMTP access and get an authorization code. This code is your login password by default. If you have enabled the security password feature for third-party clients, use that password instead.

Code examples

The following are code examples for sending emails using SMTP:

SMTP email delivery code example for Python 3.6 and later

SMTP email delivery code example for Java

SMTP email delivery code example for PHP

SMTP email delivery code example for C#

Note

For batch or system-triggered emails, we recommend that you use Direct Mail (What is Direct Mail?) to avoid a negative impact on your enterprise email reputation, which can affect the delivery of your regular emails.

Troubleshooting

If you complete the configuration but cannot send emails, check the following:

  • Verify that your account and password are correct and do not contain extra characters.

  • If you use port 465, make sure that SSL encryption is enabled.

  • Verify that the server address is correct.

  • SMTP sending is enabled by default. If it is disabled, follow the instructions provided earlier.

  • Check your code logic. We recommend first testing the provided code examples with hardcoded parameters.

Note

To verify your configuration information, such as the server address, port, account, and password, try using the same settings in a third-party email client.

If you can send emails from a client but not from your program, review your code for logic errors.