You are on page 1of 2

How Is Sending SMS Through Java Possible?

Marketers say that combined approach over all channels is essential. If a company wants
to reach their target audience in todays IT world, then they need to develop
incorporated internet marketing strategies. For developing a strong and marketable brand,
this strategy should link responsive web design, mobile applications, SMS marketing,
with direct marketing, email marketing, etc.
Since Java has endemic method calls to send HTTP requests, HTTP provides the best
way to send SMS messages to distant mobile devices. The three major participants of the
Java SMS solution are following:
1. Your Java SMS application:
Java SMS application is a software developed in Java that can be used to deliver
messages. A basic SMS application can be freely extended as per your requirements. You
can use HTTP to create a connection between Java application and SMS Gateway that
allow you Sending SMS using Java.
2. SMS Gateway:
An SMS gateway allows your system to send or receive SMS to or from a
telecommunications network. It is able to send an SMS coming from your Java
application through HTTP to the Short Message Service Center (SMSC) of the mobile
service provider via SMPP IP SMS connection or a GSM modem. To be able to deliver
SMS messages using HTTP, you will require an Bulk SMS gateway that has a built-in
server. It allows you to deliver SMS from your application by calling a URL or through
HTTP Post method.
3. Mobile phone user:
This is the final point in case of delivering SMS messages. This is the receiver of SMS
you wish to send and that can be your client, your business partner, a colleague, a friend
or any other. The Transactional SMS that has been delivered from your Java application
will be sent to the mobile number of this user.
The use of third-party solutions or shrink-wrapped Java Software Development Kits gives
a very easy and effective method for sending and receiving Transactional SMS. Always
keep in mind that major solutions will have licensing and usage fees because carriers set
their own final cost. Integrating SMTP will definitely provide a low-priority path to a
restricted number of wireless devices, but the number of email-supporting devices is very
low on an international level. The use of SMTP also creates different serious yet hidden
clashes with the delivery of text-messages. If reliability, performance, and scalability are
significant concerns when integrating text-messaging into your own applications, then
seeking a third-party component like MSG91 may be your ultimate solution!

//Your authentication key


String authkey = "YourAuthKey";
//Multiple mobiles numbers separated by comma
String mobiles = "9999999";
//Sender ID,While using route4 sender id should be 6 characters long.
String senderId = "102234";
//Your message to send, Add URL encoding here.
String message = "Test message";
//define route
String route="default";
//Prepare Url
URLConnection myURLConnection=null;
URL myURL=null;
BufferedReader reader=null;
//encoding message
String encoded_message=URLEncoder.encode(message);
//Send SMS API
String mainUrl="https://control.msg91.com/api/sendhttp.php?";
//Prepare parameter string
StringBuilder sbPostData= new StringBuilder(url);
sbPostData.append("authkey="+authkey);
sbPostData.append("&mobiles="+mobiles);
sbPostData.append("&message="+encoded_message);
sbPostData.append("&route="+route);
sbPostData.append("&sender="+senderId);
//final string
mainUrl = sbPostData.toString();
try
{
//prepare connection
myURL = new URL(mainUrl);
myURLConnection = myURL.openConnection();
myURLConnection.connect();
reader= new BufferedReader(new InputStreamReader(myURLConnection.getInputStream()));
//reading response
String response;
while ((response = reader.readLine()) != null)
//print response
System.out.println(response);
//finally close connection
reader.close();
}
catch (IOException e)
{
e.printStackTrace();
}

You might also like