Sending Text Messages with Alibaba Cloud SMS


  1. An enterprise Alibaba Cloud account
  2. A RAM account with AliyunDysmFullAccess policy attached
  3. A mobile phone number which can receive SMS
  4. Some programming skill (java in this example)
  • accessKeyId: RAM account's access key
  • accessKeySecret: RAM account's Secret
  • tel: Telephone number you would send the SMS to
package com.alicom.dysms.api;import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20180501.QuerySendDetailsRequest;
import com.aliyuncs.dysmsapi.model.v20180501.QuerySendDetailsResponse;
import com.aliyuncs.dysmsapi.model.v20180501.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20180501.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
* Created on 2018.05.01
* The is a DEMO that introduces how to use SMS send Api and SMS query Api.
* Two jar packages are required,please put them in the libs directory
* 1:aliyun-java-sdk-core.jar
* 2:aliyun-java-sdk-dysmsapi-inter.jar
* notice : The Program was encoded with standard of UTF-8
public class SmsDemo {
// product name, please remain unchanged
static final String product = "Dysmsapi";
// product domain, please remain unchanged
static final String domain = "";
// AccessKey and AccessKeySecret , you can login sms console and find it in API Management
static final String accessKeyId = "use your Key id";
static final String accessKeySecret = "use your Key Secret";
static final String tel = "yourphonenumber with IDD prefix";
public static SendSmsResponse sendSms() throws ClientException {
try {
System.setProperty("", "10000");
System.setProperty("", "10000");
IClientProfile profile = DefaultProfile.getProfile("ap-southeast-1", accessKeyId, accessKeySecret);
DefaultProfile.addEndpoint("ap-southeast-1", "ap-southeast-1", product, domain);
IAcsClient acsClient = new DefaultAcsClient(profile);
// initiate the SendSmsRequest, read help documents for more parameters instructions
SendSmsRequest request = new SendSmsRequest();
// send to
// ContentCode , you can login sms console and find it in Content Management
request.setContentCode("SMS_10350063"); // this should match the content code shows in sms console
// set the value for parameters in sms Content with JSON format. For example, the content is "Your Verification Code : ${code}, will be expired 5 minutes later"
// Optional,custom field, this value will be returned in the sms delivery report.
SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request); return sendSmsResponse;
} catch (Exception e) {
return null;
public static void main(String[] args) throws ClientException, InterruptedException { // send sms
SendSmsResponse response = sendSms();
System.out.println("send sms response----------------");
System.out.println("Code=" + response.getResultCode());
System.out.println("Message=" + response.getResultMessage());
System.out.println("RequestId=" + response.getRequestId());
System.out.println("BizId=" + response.getBizId());

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns=""



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alibaba Cloud

Alibaba Cloud


Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website: