How to send and receive SMS in java?

If you want to send and receive an SMS using java code then, first of all, you have to write a java code that supports your API. You can also use Java code of MSG91 to send bulk SMS. Here we will guide you about how to send and receive messages in Java language by using a mobile phone, desktop, laptop through the internet connection.

Designed a Java application and add SMS functionality to it. Then set up a proper configuration where you can send and receive text messages using database server like Oracle, MSSQL, MySql etc.

You can share data tables that are available on the database server between your Java application and an SMS gateway so that your Java application can easily send messages by reading and creating database records. You can use this method only if you have created two database tables inside the database server. One table for storing incoming messages and another table for storing outgoing SMS messages.

If you have taken an SMS gateway from MSG91 then you can store receives a message and sent messages in it. Similarly, if you want to send messages from Java code, you should store it in a table so that your SMS gateway software will read the database table periodically. You can add, deleted or edit your database table easily. One of the advantages of this method is that all of your SMS will automatically archive and easily supervise that which message is delivered successfully.

How to send and receive SMS in java?

How to send and receive SMS in java?

How to send and receive SMS in java?

Step by step procedure to send an SMS by using Java application:

1 Connect to MySQL database and create the database layout

2 Install and configure MSG91 SMS Gateway

3 Creating your Java application

4 Use the given Java code to design your application.

public class SendSms{

public static void main(String[] args)
//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=””;

//Prepare parameter string
StringBuilder sbPostData= new StringBuilder(mainUrl);

//final string
mainUrl = sbPostData.toString();
//prepare connection
myURL = new URL(mainUrl);
myURLConnection = myURL.openConnection();
reader= new BufferedReader(new InputStreamReader(myURLConnection.getInputStream()));
//reading response
String response;
while ((response = reader.readLine()) != null)
//print response

//finally close connection
catch (IOException e)

Note: If you will change the database connection details like dbHost, dbUsername, dbPassword, and database then you have to enter different mobile number for sending the SMS message.

By following this method, you can easily send and receive bulk SMS by using Java application. Still, if you found and query related to this topic then you can send your query in a comment box. We will try to solve your query as soon as possible.