Implementation of SMS using twilio in java
Posted By : Murari Kumar | 16-May-2016

I had the requirement of the sending messages on mobile number for the two factor authentication. For this requirement i have used twilio which is given by third party.
Twilio is used for send messages to moblie number. With the twilio developer can easily send and receive messages programatically.If I want to use twilio then first of all we need to register in twilio site and we get account_sid and Authentication token from twilio.After getting account_sid and authentication token, we need to follows these code :--
public Message getMessage(Long to,String body) throws TwilioRestException{
String ACCOUNT_SID="xxxxxxxxxxxxxxxxxxxxxxxx";
String AUTH_TOKEN-"xxxxxxxxxxxxxxxxxxxxxxxx";
TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);
Account account = client.getAccount();
MessageFactory messageFactory = account.getMessageFactory();
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("To","+91"+8927444816)); // Replace with a valid phone number for your account.
params.add(new BasicNameValuePair("From", "+16317146088")); // Replace with a valid phone number for your account.
params.add(new BasicNameValuePair("Body","Body of message"));
Message sms = messageFactory.create(params);
return sms;
}
If we are using trial version of the twilio(unpaid service) then we need to register receiver mobile number into twilio site.If you are using paid version then this restriction is not applied.
THANKS
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Murari Kumar
Murari is a bright Web developer. He has expertise in Java.