• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 546
  • Last Modified:

Sending SMS from Java

How to send SMS using Java API? (If someone can help with free SMS in India, it would be great)
On a wider note, how to interface with Mobile network using desktop Java? Is it possible?
Could we call/divert mobile call using Java on desktop?
1 Solution
prerakshethAuthor Commented:
Thanks, but I should have added to my original question - "Thru internet".
In other words, I would like to send SMS thru internet to a desired number(or a set of numbers)
SAMIR BHOGAYTAFreelancer and IT ConsultantCommented:
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Gurvinder Pal SinghCommented:
@samirbhogayta: please check my previous reply. The link that you have posted is the first link that i posted in my previous reply.
prerakshethAuthor Commented:
The solution is useful, but does not answer my original question completely about a free sms service in India. Anyhow, this is probabaly the closest that we can get
Here is some information on sending from Java. The messages are not free, but you do get a free trial account.


Java API

Use this API to send text messages from Java.

 Simple HTTP request
 Encrypted communication over SSL
 Long SMS (up to 765 characters)
 Delivery status via function return code
 Email replies


public static int  SendSMS(String strAccountId,String strEmail,String strPassword,
String strMSISDN,String strMessage,StringBuffer strResponse)
      String  sRequestURL;
      String  sData;
      int nResult = -1;

      sRequestURL = "http://www.redoxygen.net/sms.dll?Action=SendSMS";

            sData  = ("AccountId="  + URLEncoder.encode(strAccountId,"UTF-8"));
            sData += ("&Email="     + URLEncoder.encode(strEmail,"UTF-8"));
            sData += ("&Password="  + URLEncoder.encode(strPassword,"UTF-8"));
            sData += ("&Recipient=" + URLEncoder.encode(strMSISDN,"UTF-8"));
            sData += ("&Message="   + URLEncoder.encode(strMessage,"UTF-8"));

            URL urlObject = new URL(sRequestURL);
            HttpURLConnection con = (HttpURLConnection) urlObject.openConnection();
            con.setDoInput (true);
            con.setDoOutput (true);

            DataOutputStream out;
            out = new DataOutputStream(con.getOutputStream());
            out.writeBytes (sData);
            BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
            String inputLine;
            StringBuffer responseBuffer = new StringBuffer();

            while ((inputLine = in.readLine()) != null)
                  responseBuffer = responseBuffer.append(inputLine);
                  responseBuffer = responseBuffer.append("\n\n\n");

            String sResultCode = strResponse.substring(0,4);
            nResult = Integer.parseInt(sResultCode);
      catch (Exception e)
            System.out.println("Exception caught sending SMS\n");
            nResult = -2;
      return nResult;
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now