All Products
Document Center

Java SDK tutorial

Last Updated: Jan 20, 2022

Create an AccessKey

  1. Log on to the

    AccessKey console


  2. Click Create AccessKey at the upper-right corner of the page.

  3. Read API Terms of Use, and then click Agree and Create.

Note: You can use the AccessKey created with Alibaba Cloud Resource Access Management service.

Install the Java SDK

Development environment

Alibaba Cloud Java SDK supports J2SE Development Kit (JDK) 1.6 or later.

Download the SDK

Install the SDK

Install manually

  1. Find the files “aliyun-java-sdk-dm-3.0.0-rc1.jar” and “aliyun-java-sdk-core-3.0.0.jar” in the downloaded package.

  2. Add JARS.Take importing the JAR package in Eclipse as an example:

    On Eclipse, right-click Project, and click Properties > Java Build Path > Libraries > Add External JARs (other idea users including “netbeans” and “intellij” must follow the appropriate method to import the JAR package).

  3. Select the JAR packages and click OK.

Now you can use the Alibaba Cloud Java SDK in the project.

Install using maven

  1. Add the maven library.

                 <name>Sonatype Nexus Staging</name>
  2. Add a JAR package.


Email sending example

Take calling the API to send a single email as an example (for how to call the interface, see SingleSendMail):

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;

public class Sample {

    public void singleSendMail() {       
        IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", "<your accessKey>", "<your accessSecret>");//ap-southeast-1,ap-southeast-2
        //Encrypted connections using HTTPS
        // Other region except China east 1 (hangzhou), such as Singapore region, need to do the following treatment.
        //try {
        //DefaultProfile.addEndpoint("", "ap-southeast-1", "Dm",  "");
        //} catch (ClientException e) {
        IAcsClient client = new DefaultAcsClient(profile);
        SingleSendMailRequest request = new SingleSendMailRequest();
        try {
   //request.setVersion("2017-06-22");//  Other region except China east 1 (hangzhou), such as Singapore region, need to be specified for the 2017-06-22.
            request.setAccountName("Mail address created in the console");
            request.setFromAlias("Sender nickname");
            request.setTagName("Tag created in the console");
            request.setToAddress("Destination address");
            request.setMethod(MethodType.POST);//If the size of Textbody, htmlbody or content is uncertain, it is recommended to submit it by post to avoid URI is not valid exception
   //request.setClickTrace("0");//0 off, 1 on  ClickTrace
            SingleSendMailResponse httpResponse = client.getAcsResponse(request);
        } catch (ServerException e) {
   System.out.println("ErrCode : " + e.getErrCode());
        catch (ClientException e) {
   System.out.println("ErrCode : " + e.getErrCode());

Click here to get more tips for using Java SDKs.