Last active
December 20, 2015 03:09
-
-
Save EsendexDev/6061277 to your computer and use it in GitHub Desktop.
How to create and send an SMS message with the Esendex Java SDK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Create an SMS message request with phone number and message body | |
SmsMessageRequest msg = new SmsMessageRequest("447879000000", "my body text"); | |
//Add optional fields to the message | |
msg.setBody("Test Message from SendMessageSample"); | |
msg.setFrom("447879000000"); | |
msg.setValidity(5); | |
//Create a collection to hold the single message to send from specified account | |
SmsMessageCollectionRequest req = new SmsMessageCollectionRequest("myAccountReference", msg); | |
//Add optional fields that apply to all messages | |
req.setFrom("447879999999"); | |
//Create a factory for creating services based on preferred authentication strategy | |
UserPassword userPassword = new UserPassword("MyUsername", "MyPassword"); | |
BasicServiceFactory factory = ServiceFactory.createBasicAuthenticatingFactory(userPassword); | |
//Get the service for sending messages | |
MessagingService service = factory.getMessagingService(); | |
//Call sendMessages() to execute the service request and obtain a response | |
MessageResultResponse resp; | |
try { | |
Date sendAt = new SimpleDateFormat("dd-MM-yyyy").parse("01-10-2013"); | |
resp = service.sendScheduledMessages(req, sendAt); | |
} catch (EsendexException ex) { | |
ex.printStackTrace(); | |
return; | |
} | |
//Call getMessageIds() on the response to get the list of message responses | |
List<ResourceLinkResponse> messages = resp.getMessageIds(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment