Your Java application can send SMS for free

By

September 19, 2010Programming36 Comments

The problem with sending text to mobiles from your java program is that you’ve to spend few bucks buying GSM Modem, buy SIM with free SMS option and then connect it with Java Communication API. So here is a simple API that uses the help of way2sms service to send free SMS.

Credits to Aswin Anand and Sailesh Soliwal for developing the API

Steps:

1) Download the jar file from http://www.mediafire.com/?ztwzzwmfmmz

2) Add the jar file to library in your Netbeans or Eclipse IDE.

3) To send SMS call the Send() method of smsclient class.

4) Here is a sample implementation.

import com.way2sms.SMS;
class TestSMS {

public static void main(String[] args) {

SMS smsClient=new SMS();
smsClient.send( Username, Password, Number, Message,Proxy);
}
}

Where,

  • Username & Password are Your way2sms username and password
  • Number is recipient’s mobile number
  • Message is the text to be sent
  • and Proxy is the address of the proxy server. If you are using at home leave the proxy field as “” or null

If you are using it in your college lab then you’ll have to connect internet with the help of proxy. But in my lab I couldn’t connect since my proxy server required authentication. If you can solve it please leave as comment.

The author Sailesh Soliwal has made few applications with this API. You can check it here.

If you are a web developer and require a similar API, don’t worry. You can use the same JAR file if your server has Java virtual machine or else Aswin Anand has given you a free php script. Check it here.

36 Responses to “Your Java application can send SMS for free”
  1. nir

    i cant receive the msg. though programs runs without any error..plus if i enter my password wrong, then also its not showing any error .

    • Jeyaganesh

      the api works good till now.. a change in api will do such errors.

    • Jeyaganesh

      the api works good till now.. a change in api will do such errors.

    • Abhishek

      Right Nir — I have faces same problem ;

  2. Mudit

    not working….
    though i am entring the correct username and pwd it shows ‘Login Failed’..
    can you tell me what could be the problem??

  3. jinesh

    this code is not sending any type of messge it will just print simple message that the message send to this person it not send actually to the mobile which i send to person

    • Jeyaganesh

      Jinish. I guess the api is outdated.Will try to figure out soon

      • Nikunj

        He sir you code is runing withou error but msg will not send in my mobile pls help me
        my email id is : nikunjrathod77@gmail.com

        its not working 4 me… stucks at

        [Logging in …]
        [Login Successful…]
        [Number of messages to be sent = 1]
        [(1 out of 1) Sending message to : 9884536705]

  4. jayesh

    i was try to run this program and it is run but not any msg send or receive in my mobile.
    plz help me.

  5. Nikunj

    He sir you code is runing withou error but msg will not send in my mobile pls help me

    its not working 4 me… stucks at

    [Logging in …]
    [Login Successful…]
    [Number of messages to be sent = 1]
    [(1 out of 1) Sending message to : 9884536705]

  6. aman

    refer this site…U will got the solution…………….
    http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=6866&lngWId=2

  7. Jeyaganesh

    This way2sms api maybe outdated. See http://goo.gl/vYhpX that works using c#

  8. suresh

    connection.getHeaderField(“Set-Cookie”); in SMS.class is returning null.can u tell me how resolve it .Please it is very urgent for me .

  9. suraj

    Not able to send sms
    It prints the following errors:-
    Logging in …
    Login Failed…
    java.io.FileNotFoundException: http://wwwd.way2sms.com//auth.cl
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1239)
    at com.way2sms.SMS.login(SMS.java:132)
    at com.way2sms.SMS.send(SMS.java:75)
    at TestSMS.main(TestSMS.java:7)

  10. valiyullah

    @ Suraj -I am too getting the same issue πŸ™

    Let me know if anyone found the solution.

    Thanks in advance..

  11. Renjith

    Me also got the same error… plz help me.. plzzzz……
    ERROR IS:

    Login Failed…
    java.io.FileNotFoundException: http://wwwd.way2sms.com//auth.cl
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1434)
    at com.way2sms.SMS.login(SMS.java:132)
    at com.way2sms.SMS.send(SMS.java:75)
    at TestSMS.main(TestSMS.java:7)

  12. renjith

    @ Suraj & @valiyullah
    Me also getting the same issue πŸ™

    Let me know if anyone found the solution.

    plzzzzzzzz……..

  13. renvarabhraj

    SIR….
    Plz explain what is the problem…
    ERROR is…

    Logging in …
    Login Failed…
    java.io.FileNotFoundException: http://wwwd.way2sms.com//auth.cl
    Number of messages to be sent = 1
    (1 out of 1) Sending message to : 9447651433
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1434)
    at com.way2sms.SMS.login(SMS.java:132)
    at com.way2sms.SMS.send(SMS.java:75)
    at com.way2sms.start.main(start.java:7)
    Failure: SMS Sent Failed.
    java.io.FileNotFoundException: http://wwwd.way2sms.com/FirstServletsms?custid=
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1434)
    at com.way2sms.SMS.sendMessages(SMS.java:225)
    at com.way2sms.SMS.send(SMS.java:78)
    at com.way2sms.start.main(start.java:7)

  14. ramesh

    java.net.UnknownHostException: wwwd.way2sms.com
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:177)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
    at java.net.Socket.connect(Socket.java:529)
    at java.net.Socket.connect(Socket.java:478)
    at sun.net.NetworkClient.doConnect(NetworkClient.java:163)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:394)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:529)
    at sun.net.www.http.HttpClient.(HttpClient.java:233)
    at sun.net.www.http.HttpClient.New(HttpClient.java:306)
    at sun.net.www.http.HttpClient.New(HttpClient.java:323)
    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:860)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:801)
    at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:726)
    at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:904)
    at com.aswinanand.sms.SMS.send(SMS.java:71)
    at com.SendSms.main(SendSms.java:14)

    HI i am facing the following issue.. please help me on this..

  15. suraj

    Actually the problem is:
    that java api uses way2sms gateway which is old (way2sms team changed the gateway).
    I searched in google for such free gateway, but in vain. All other company charges for their own gateway. So if u want, u can buy their gateway and can send sms.

    • Rajeshwaran

      Thank you so much ! For your Information . Is there any other JAVA SMS FREE API . I wanna send sms via java code . Plz. help . Thanks in advance

    • SIVA

      done

  16. praveend76

    same problem:(

  17. Kulin Shah

    I think in case of so many failures listed above it is best to use the main website of way2sms to send messages

    πŸ™‚

  18. Jeyaganesh

    If you face any problem in sending sms using java you can try using it in PHP.
    http://devlup.com/programming/php/send-sms-using-way2sms-php-api/4254/

  19. atul

    sir pls tell me inplace of username ,password what should we write.

    • Jeyaganesh

      You should use your way2sms username and password.

  20. richu

    Apr 08, 2016 9:34:25 AM java.util.prefs.WindowsPreferences
    WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0
    x80000002. Windows RegCreateKeyEx(…) returned error code 5.
    Exception in thread “main” java.lang.NullPointerException
    at com.way2sms.SMS.setupProxy(SMS.java:412)
    at com.way2sms.SMS.send(SMS.java:72)
    at TestSMS.main(TestSMS.java:11)

    this response

  21. richu

    the below are my errors
    Apr 08, 2016 9:34:25 AM java.util.prefs.WindowsPreferences
    WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0
    x80000002. Windows RegCreateKeyEx(…) returned error code 5.
    Exception in thread “main” java.lang.NullPointerException
    at com.way2sms.SMS.setupProxy(SMS.java:412)
    at com.way2sms.SMS.send(SMS.java:72)
    at TestSMS.main(TestSMS.java:11)

  22. Athish

    Kindly let me know if I can send sms with my own sender-id?

  23. tmann

    Logging in …
    null
    Login Failed…
    Cookies is return null
    please help me sir……

  24. Manoj Kumar

    Logging in …
    null
    Login Failed…

    What is happening here

  25. Ferry

    how to get smsclient class??

  26. Kalpesh

    Sir i am trying same code but it show :
    run:
    Logging in …
    null
    Login Failed…
    BUILD SUCCESSFUL (total time: 0 seconds)

    please suggest me what is going wrong.?

    thanks in advance.

  27. devi

    i got below error. Please tell me any one……..

    Logging in …
    Login Successful…
    Failure: Failed to connect to way2sms.com, Check your internet connection/proxy.

  28. divya

    Exception in thread “main” java.lang.NullPointerException
    at com.way2sms.SMS.setupProxy(SMS.java:412)
    at com.way2sms.SMS.send(SMS.java:72)
    at com.gst.otp.TestSMS.main(TestSMS.java:9)

    where i have did wrong and how can i handle this error.

Leave a Reply

*