Home    
Home  >  Tutorials  >  Sms

How to send SMS messages in Java

In this tutorial, we'll show you how to send SMS messages from Java using DataKnowl Cloud SMS.

Sign up for a DataKnowl Cloud Services Account


Signing up for a DataKnowl Cloud account is fast and easy. Sign up here .

SMS Dashboard


Click on SMS icon to enter the SMS Dashboard. From the dashboard you have access to sender identities, rid(s), as well as Quick Send feature and form for request new sender identities.



For each approved sender id, you've the RID (resource id) to use in API calls. For example, in the following image, you've 'Acme' sender id (alphanumeric), and its own RID.





Sender Identity


To send SMS using DataKnowl, you need a sender identity. It can be a phone number, or an alphanumeric string to be used as alphanumeric sender id.

Both number or alphanumeric ids must be approved before starting sending sms.

Approval is fast. You've only to submit the desidered number or alphanumeric sender id, and wait for the approval. After the identity has been approved, it will be usable for all sendings.



Quick Send


With 'Quick Send' you can send SMS directly from the interface. It is fast and easy.



Java Code Example


The fastest way to send SMS messages using Java, is to use the DataKnowl Cloud Services Java SDK.

You can download Java SDK from here: DataKnowl-Cloud-Java-SDK

Sending SMS is very easy, simply call 'send' method, as in the following code snippet:


package com.dataknowl.dcs.demo.sms;

import com.dataknowl.dcs.sdk.client.Auth;
import com.dataknowl.dcs.sdk.client.Region;
import com.dataknowl.dcs.sdk.sms.DcsSmsClient;
import com.dataknowl.dcs.sdk.sms.SmsClient;
import com.dataknowl.dcs.sdk.sms.model.SmsSendResult;

/**
 *
 * @author Complexity Intelligence, LLC
 */
public class SmsSend {

    public static void main(String[] args) {
        
        String accessKeyId = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        String secretAccessKey = "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY";

        String fromId = "SMSIPxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
        String to = "+1234567890";
        String body = "Hi Mark, your current balance is $578";
        
        SmsClient smsClient = DcsSmsClient.build(
                new Auth(accessKeyId, secretAccessKey), Region.EU_CENTRAL);
        
        SmsSendResult result = smsClient.send(fromId, to, body);

        System.out.println("Result code = " + result.getStatus());
        System.out.println("Result msg = " + result.getMessage());
    }
    
}




POST Parameters:

Name Description
from:id RID of the sender identity you want to use for sending
to recipient phone number, in E.164 format.
body Content of message


API Credentials


In order to sign your api requests, you need the accessKeyId and secretAccessKey. Click on 'IAM' icon:



Here, there is a list of API credentials for your account. Use the default one. Click on the lock icon.



From this page, you've both accessKeyId and secretAccessKey required to sign your API calls.



© 2019 Complexity Intelligence, LLC