All Products
Search
Document Center

Direct Mail:SDK guide

Last Updated:Dec 09, 2025

This topic explains how to install and use the Direct Mail SDK.

You can use OpenAPI to call, query, and debug Direct Mail API operations, and generate sample code.

The basic steps are as follows:

Go to the OpenAPI debugging page

The following example shows how to use the API operation to send emails:

Send an email (debug and view sample code)

To send a single email:

Debugging entry points and sample code:

https://api.alibabacloud.com/api/Dm/2015-11-23/SingleSendMail

Note

Looping and concurrent calls are supported.

A single request supports up to 100 recipient addresses. For more information about other parameters, see SingleSendMail.

Send batch emails:

Debugging entry points and sample code:

https://api.alibabacloud.com/api/Dm/2015-11-23/BatchSendMail

Note

You can use templates and recipient lists that you created in the console or by calling an API to send batch emails. For more information about other parameters, see BatchSendMail.

Query for the API operation and specify parameters

We recommend that you use the default API version 2015-11-23. This version receives continuous optimizations and updates without a change in the version name.

image

For more information, see the API documentation.

image

Select a programming language and debug

You can select a programming language and click Make Call.

image

Generate sample code for the call

Method 1: Use the Direct Mail SDK

Obtain the SDK installation command

After the test completes successfully, install the SDK on your local machine or test server.

In the SDK Information section, you can view the version and installation command for the Direct Mail SDK.

image

image

Method 2: Use CommonRequest

Switch to Common Mode to generate sample code. In this mode, parameters are passed in the request body by default instead of the URL, which prevents requests from being blocked due to an excessively long URL.

image

C# example:

The "Invalid URI: The Uri string is too long" error occurs when you use the C# SDK to send long content

References

Java generalized calls 1.0 (Deprecated)

Java Generalized Calls 2.0

Other considerations

Create an AccessKey

After you log on with your Alibaba Cloud account, you do not need to specify a key on the debug page. However, you must configure the key in your code to run it on a local machine or a server.

(Note: Alternatively, you can use an AccessKey from the Resource Access Management (RAM) service.)

  1. Log on to the AccessKey Management console.

  2. In the upper-right corner of the page, click Create AccessKey. The Create dialog box opens.

  3. Read the prompt and click OK.

Warning

Do not hard-code the `accessKeyId` and `accessKeySecret` values in your code to prevent them from being leaked.

You can configure the `ALIBABA_CLOUD_ACCESS_KEY_ID` and `ALIBABA_CLOUD_ACCESS_KEY_SECRET` values as environment variables in your operating system. The Alibaba Cloud SDK retrieves these values from the environment variables for identity verification. For more information, see Identity verification configuration.