All Products
Search
Document Center

Direct Mail:Enable data tracking

Last Updated:Jun 04, 2026

Enable tracking to collect open and click event data for emails you send through Direct Mail.

How tracking works

Open tracking and click tracking use different mechanisms:

  • Open tracking: Direct Mail embeds a transparent image in the email. When a recipient opens the email, the image loads and an open event is recorded.

  • Click tracking: Direct Mail replaces eligible links with redirect URLs that route through the Direct Mail tracking service. When a recipient clicks a tracked link, the service records the event and redirects the recipient to your original URL.

    1. Open and click event data is collected in real time and displayed in the console.

Prerequisites

Before you begin, make sure that you have:

  • A sender domain with Verified status

  • An email tag created on the Set Email Tag page, referenced when sending

Email requirements

Your email must meet the following requirements before you enable tracking:

  1. Use an existing email tag.

  2. Use HTML email format. The email body must include a <body> element, for example: <body>Your email content</body>.

  3. For click tracking, links must be HTML <a> tags in the HTML body, for example: <html><body><a href="hyperlink_to_track">test</a></body></html>. Links must be publicly accessible and start with http:// or https://.

Enable tracking

Send emails from the console

  1. When creating an email sending task, select the Enable checkbox for email tracking.

image

  1. Make sure the email content meets the requirements listed above.

Send emails by API or SDK

  1. Set the Tag parameter to an existing email tag and the ClickTrace parameter to "1".

  2. Set the email body using the setHtmlBody method. Make sure the content meets the requirements listed above.

Note

To verify tracking is active, check the raw email content for an img tag (open tracking) or a tracking link (click tracking) at the end of the body.image

Send emails by SMTP

Set the X-AliDM-Trace header as described in Track email open data by tag when sending by SMTP. Use the following values:

Header field

Value

Tag

An existing email tag

OpenTrace

"1"

LinkTrace

"1"

Note

To exclude a specific link from click tracking, add the data-alidm-traceoff attribute to its <a> tag in the HTML content. For example:

<a href = "http://www.aliyun.com" data-alidm-traceoff>Alibaba Cloud</a>

SMTP requirements

  1. The MIME type of the email body must be text/html;charset=UTF-8. Set the Content-Transfer-Encoding header to quoted-printable. Make sure the content meets the requirements listed above.

Python example:

from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
msg = MIMEMultipart('alternative')
texthtml = MIMEText('''<html><body><a href="https://www.aliyun.com">Email Tracking</a></body></html>''', _subtype='html',
                    _charset='UTF-8')
if 'Content-Transfer-Encoding' in msg:
    # If the header is already set, replace the first value (this header usually has only one value).
    msg.replace_header('Content-Transfer-Encoding', 'quoted-printable')
else:
    # If the header is not set, add it.
    msg['Content-Transfer-Encoding'] = 'quoted-printable'
msg.attach(texthtml)

SMTP call example for Python 3.6 and later

Java example:

import javax.mail.internet.MimeBodyPart;
// Assume that msg is the MimeMessage object you are working with. This example uses MimeBodyPart for demonstration.

// Create the message body part.
MimeBodyPart textPart = new MimeBodyPart();
textPart.setContent("<html><body><a href=\"https://www.aliyun.com\">Email Tracking</a></body></html>", "text/html; charset=UTF-8");
// Check if 'Content-Transfer-Encoding' is set.
String[] cte = textPart.getHeader("Content-Transfer-Encoding");
if (cte == null || cte.length == 0) {
    // If not set, add the header.
    textPart.addHeader("Content-Transfer-Encoding", "quoted-printable");
} else {
    // If it is set, replace the first value (this header usually has only one value).
    textPart.setHeader("Content-Transfer-Encoding", "quoted-printable");
}

SMTP call example for Java