Alibaba Mail API Open Platform
Alibaba Mail API Open Platform lets enterprise systems and automation scripts use Alibaba Mail capabilities through documented APIs. It covers organizations, domains, users, departments, mail groups, shared contacts, mail, calendars, login, audit logs, file streams, quarantine, and rules. Typical use cases include account lifecycle management, organization sync, mail and calendar automation, security audits, quarantine handling, internal admin tools, and batch scripts.
The Free Edition of Alibaba Mail does not support the API Open Platform. Before using the APIs, an enterprise administrator must create an application in the admin console, grant API permissions, and protect the application credentials.
Integration Model
- In the admin console, open Advanced Applications or API Open Platform and create an application.
- Grant the minimum required scopes, such as
User.ReadWrite.All,Department.Read.All,Mail.Read.All,Mail.Send.All, andCalendar.ReadWrite.All. - Obtain the application's
client_idandclient_secret, then exchange them for an access token through the OAuth2 client credentials flow. - Send business API requests with the
Authorization: Bearer <access_token>header. - Use the Base URL shown on the API page for the enterprise region and current environment:
https://alimail-cn.aliyuncs.com. Never reuse an address across clusters.
Get Access Credentials
Obtain an Authorization Token
Before calling Alibaba Mail APIs, create an application in API Open Platform in the Alibaba Mail admin console and grant it the required permissions. Then use the application's client_id and client_secret to call the authorization endpoint and obtain an authorization token. The request is as follows:
POST /oauth2/v2.0/token HTTP/1.1
Host: alimail-cn.aliyuncs.com
Content-Type: application/x-www-form-urlencoded
grant_type=client_credentials&client_id=<client_id>&client_secret=<client_secret>
Request parameters:
| Parameter | Required | Description |
|---|---|---|
grant_type | Y | Fixed value: client_credentials. |
client_id | Y | The application ID used to request an authorization token. The enterprise administrator obtains it after registering the application in the admin console. |
client_secret | Y | The application secret used to request an authorization token. The enterprise administrator obtains it after registering the application in the admin console. Do not disclose it: anyone with the application ID and secret can call APIs as that application. |
Response parameters:
| Parameter | Description |
|---|---|
token_type | Token type. Currently always bearer. |
access_token | Authorization token. |
expires_in | Authorization token lifetime in seconds. Cache the token and request a new one after it expires. |
Request example (curl):
curl -X POST \
'https://alimail-cn.aliyuncs.com/oauth2/v2.0/token' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'grant_type=client_credentials&client_id=<client_id>&client_secret=<client_secret>'
Request example (Java, using OkHttpClient):
OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
RequestBody body = RequestBody.create(
mediaType,
"grant_type=client_credentials&client_id=<client_id>&client_secret=<client_secret>"
);
Request request = new Request.Builder()
.url("https://alimail-cn.aliyuncs.com/oauth2/v2.0/token")
.post(body)
.addHeader("Content-Type", "application/x-www-form-urlencoded")
.build();
Response response = client.newCall(request).execute();
Response example:
{
"token_type": "bearer",
"access_token": "...",
"expires_in": 172799
}
Pass the Authorization Token to API Calls
Every Open API call must include a valid authorization token in the HTTP Authorization request header. Prefix the token value with Bearer.
Request example:
curl -X POST \
'https://alimail-cn.aliyuncs.com/...' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <access_token>' \
...
API Traffic Limits
The aggregate API traffic of all applications in a single domain must not exceed 40 requests per second. Requests over the limit return HTTP status 429.
Core Concepts
| Concept | Definition |
|---|---|
| Organization | The top-level enterprise mailbox tenant. It contains domains, users, departments, mail groups, shared contacts, and other resources. |
| Domain | The domain used for enterprise mail sending and receiving. Domain APIs create, query, verify, and manage enterprise domains. |
| User | A mailbox account. User APIs cover account creation, profile updates, password reset, aliases, security phone numbers, mailbox settings, and shared members. |
| Department | A node in the enterprise organization tree. Department sync usually starts from the root department and recursively reads sub-departments and members. |
| Mail Group | A group address and its member set, used for unified receiving, distribution, and access control. |
| Shared Contact | A contact or contact folder in the enterprise shared address book, separate from personal contacts. |
| Mail folders, message lists, message details, attachments, drafts, sending, moving, deleting, and batch updates. | |
| Calendar | Calendars, events, sharing, import/export, and meeting replies. |
| Quarantine | A temporary container between the inbox and spam/trash flows. It stores messages intercepted by anti-spam, anti-virus, or anti-phishing rules. Quarantined messages are typically retained for 30 days. |
| File Stream | Upload, download, chunking, or redirect capabilities for attachments and large files. |
| Scope | The permission range granted to an application. Each API page lists required scopes. Request the exact scopes needed by the API instead of granting broad permissions by default. |
| Cursor | A cursor-based pagination marker. List APIs often return the next cursor, and callers must continue reading until no next page is available. |
Capability Map
- Organization and domains: read organization information, update organization settings, create, query, verify, and delete domains.
- Users and departments: create accounts, update account profiles, reset passwords, manage aliases, security phone numbers, mailbox settings and shared relationships, and recursively sync department trees and members.
- Mail groups and shared contacts: manage mail groups, members, shared contacts, and shared contact folders.
- Mail: list mail folders and messages, read message details, create drafts, upload attachments, send drafts, move, copy, delete, and batch-update messages.
- Calendar: manage calendars, events, shared calendars, event import/export, and meeting invitation replies.
- Security and governance: query audit logs, process quarantined messages, and maintain inbound allow/block lists and related rules.
- Login and file streams: generate passwordless login links, invalidate login tokens, and handle attachment upload/download and file streams.
Common Workflows
Create Accounts and Sync the Organization Tree
- Query or create departments and store department IDs.
- Call the user creation API with the mailbox address, name, department, password policy, and related fields.
- If aliases, security phone numbers, or mailbox settings are required, call the corresponding user extension APIs.
- For batch sync, process data by department tree batches so organization structure writes and account writes are not mixed out of order.
Read the Complete Department Tree
- Get the root department ID. Some APIs allow
$rootto represent the root department. - Call the API that lists sub-departments.
- Recursively read each sub-department until no child nodes remain.
- If an API returns pagination fields, continue reading with the cursor or pagination parameters from the response.
Read Messages and Attachments
- Select the user mailbox and mail folder.
- Call the message list API and page by
cursor,size, sorting fields, and time range. - Call the message detail API to read the body, sender, recipients, and metadata.
- Call the attachment list API to get attachment IDs.
- Create an attachment download session, then read the attachment from the returned URL or file stream.
Create a Draft and Send Mail
The Alibaba Mail API sending flow usually creates a draft first and then sends the draft. This capability is intended for special scenarios tightly coupled to a user's mailbox. For large-scale system notifications, marketing mail, or bulk outbound mail, use a dedicated product such as Alibaba Cloud DirectMail/Mail Push.
- Create a draft with recipients, subject, body, and attachment information.
- If attachments are required, create an upload session and upload the files first.
- Call the send draft API.
- Confirm the result from the response and audit logs.
Process Quarantined Messages
Quarantine stores messages intercepted by security policies. Common actions include searching quarantined messages, reading message details, listing attachments, releasing messages to the inbox, deleting messages, and maintaining allow/block lists. Blocklist hits are usually deleted directly, while allowlist hits are usually delivered directly. Confirm scope and rule priority before changing rules.
Request and Response Conventions
- JSON request bodies and JSON responses are used by default, except for file stream APIs.
- Path parameters, query parameters, and body parameters are defined on each API page.
- Every business API requires
Authorization: Bearer <access_token>. 401usually means the token is missing, invalid, or expired.403usually means the application does not have permission for the API. Grant the required permission in the admin console.429means that the request was rate limited. The aggregate API traffic of all applications in a single domain must not exceed 40 requests per second.400,404,409, and similar errors usually includedetailErrorCodeandmessage. Scripts should read these fields instead of only checking the HTTP status.- List APIs often include
cursor,nextCursor,hasMore, andsize. Do not read only the first page.
Security Guidance
- Use least-privilege scopes and split permissions by application responsibility.
- Do not log
client_secret, access tokens, user passwords, or attachment download URLs. - Cache tokens until shortly before expiration and refresh them when needed. Do not request a new token for every business API call.
- Production scripts need retry, rate-limit handling, idempotency, and audit records.
- Add human confirmation or a small rollout scope for high-risk actions such as delete, batch update, releasing quarantined messages, or sending mail.