This topic provides a demo to describe how to use the Alibaba Cloud SDK for Java to call the SendMessageToGlobe operation. This API operation allows you to send text messages to the regions outside Mainland China.


Before you use the SDK sample code, pay attention to the following considerations:

  • When you construct the DefaultProfile class, you must use the default value of the regionId parameter. The default value is ap-southeast-1. Note that regionId is the first parameter in the DefaultProfile class.
  • You must use the default domain name:
  • You must use the default API version number: 2018-05-01.

Sample code

package com.alicom.dysms.api;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
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;
public class CommonRpc {
    public static void main(String[] args) {
        // Initialize the IAcsClient object. You can find the values of the <accessKeyId> and <accessSecret> parameters in the Short Message Service (SMS) console.
        DefaultProfile profile = DefaultProfile.getProfile("ap-southeast-1", "<accessKeyId>", "<accessSecret>");
        IAcsClient client = new DefaultAcsClient(profile);
        CommonRequest request = new CommonRequest();
        // Make sure that the domain name is
        // Make sure that the API version number is 2018-05-01.
        // Specify the API operation.
        // Required. Specify the mobile phone number to receive the text message. Note that you must add the country code to the beginning of the mobile phone number.
        request.putQueryParameter("To", "62123****8901");
        // Optional. Specify the ID of the sender.
        //request.putQueryParameter("From", "1234567890");
        // Required. Specify the text message content.
        request.putQueryParameter("Message", "have a test.");
        try {
            CommonResponse response = client.getCommonResponse(request);
        } catch (ServerException e) {
        } catch (ClientException e) {