How to Send SMS through Java code in Windows

Now a days SMS is major interactive thing in major mobile application development platform like Android, IOS, Blackberry, Symbain & Bada etc. Developers are re-imagine the way of SMS used previously. So intelligent auto sender SMS apps like ebuddy XSMS, Nimbuzz makes peoples life easier. Now a days SMS is nothing but day to day notification service. If you are a developer then here is a good chance to explore your idea using sms.For this you don’t require to BUY SMS gateways and all.You can use your mobile as middleware to avail free SMS sending service. All actions will be taken from your cell phone & you will  charge only according to your carrier SMS rates 🙂

JAVA SMS SEND CODE Working

Requirements-

1)      Multimedia mobile with its drivers installed on your computer,you must connect it through USB mode.

2)      rstxSerial.dll file (please copy this dll to your ‘C:WindowsSystem32’ folder)

3)      RXTXcomm.jar file

4)      IDE- Netbeans or Easy Eclipse

Java-SMS-Code

We are all known Netbeans and Eclipse IDE’s but Easy Eclipse for GUI purpose.

Please download required jar and dll files from following link:

Download SMS Sending JAR & DLL files

AT commands-

  • AT commands are instructions used to control a modem. AT is the abbreviation of ATtention. AT commands are also known as Hayes AT commands. There are different views to understand the meanings of “AT”. Some call it “Attention Telephone”, whereas others interpret it as “Attention Terminal” commands.
  • For execution purpose we need hyperterminal. For this run command “hypertrm.exe” .
  • If you are running this command first time you will get the following window –

Send SMS using Java Code Settings

  • Just fill first two options, click OK,  after that you will get this window-

Hyper Termianl Java code setting

 

  • If you are using Windows 7, copy these 3 files from Windows XP:-

1. C: Program Files/Windows NT/hypertrm.exe

2. C: WINODWS/system32/hypertrm.dll

3. C: WINODWS/Help/hypertrm.chm

Create folder “HyperTerminal” in C:/Program Files and paste above files in this folder. Double click on hypertrm.exe and you will get HyperTerminal in Windows 7.

Connection description Window-

  • Type any name you want and click OK.
  • Then see the option of “Connect using”, chose COM port on your mobile device gets connected.
  • (For that Go to Control Panel -> Phone and Modem Options. Then click the Modems tab. In the list box, you can see which COM port the mobile phone is connected to.)
  • Choose it and click OK.
  • You will get following windows, select “Bits per second option as 9600”. Click OK.

COM port properties-

Send SMS Java Code Comp port settings

Type following commands one by one-

  • AT  (hit enter).

(if you don’t see anything on the window, then go to File->Properties->Settings->ASCII Setup->Select check box of “Echo typed characters locally”->Click OK->Click OK.)

  • You will get a response as OK.
  • AT+CMGF=1 (hit enter).
  • AT+CMGS=”**********” ( Replace * by 10 digit mobile number to which you want to send message).
  • You will get greater than symbol like this “ > “
  • Type your message and press ctrl+z key , hit enter after this.
  • The message will be sent.

Download Java Source Code Project from following link

1. Send SMS using Java Source Code

2. For that check following window

On Hyperterminal  command execution

Java SMS send code configration Hyper Terminal

Enter Mobile Number in Double-Quotes ” “

Please close this window after using commands, because when this instance is present, we can not use it for another purpose.

Snapshots of Application To Send SMS –

(In Eclipse) :-

Send SMS using Java application interface

How to import existing project into eclipse-

  • Extract project zip file which you downloaded.
  • On eclipse, click File->Import->General->Existing project into workspace->Browse option for Select root directory-> (Suppose you extract file on the Desktop then Desktop will be the root directory , also choose ” Copy projects into workspace”)->click Finish.
  • After that you have to change the COM port number in “GUIToSendMessage.java ” file on line number 87. I have written there “COM15”. You have to change it according to your settings.
  • Run GUIToSendMessage. java file. You will see above window. Type mobile number and enter a message and click on the Send button.  The message will be sent.

How to import existing project into Netbeans-

  • Extract project zip file which you downloaded.
  • On Netbeans, click File->Import Project->Eclipse Project->Chose  option of “ Import Project Ignoring Project Dependencies ”->Browse for “Project To Import”->(here you import your project)->Browse for “Destination Folder”->(It must be your Netbeans default workspace where you store  all your Netbeans projects)->Click “Finish”.
  • After that you have to change the COM port number in “GUIToSendMessage.java ” file on line number 87. I have written there “COM15”. You have to change it according to your settings.
  • Run GUIToSendMessage. java file. You will see above window. Type mobile number and enter a message and click on the Send button.  The message will be sent.

If you are facing any problem with this code then let us know our team will help you to fix your problems ! if you develop any cool application using this code then do share with us our readers appreciate your development ! 🙂

49 thoughts on “How to Send SMS through Java code in Windows

  1. Thanks nice post.I am not a good programmer , didn’t understand clearly , let me give some more setails
    Sibin recently posted..How to check whether the sites you visit daily contains virus/malwaresMy Profile

  2. hi

    first of all i would say that you described it in very easey language and paragraph by paragraph with diagram.

    i will use this code after completed java. i am persuing java

    thanks

  3. I did all the setup but i was get a following Error:-

    java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path thrown while loading gnu.io.RXTXCommDriver
    Exception in thread “AWT-EventQueue-0” java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path

    where is the exactly problem.?
    Thanks in advance.

  4. I did all set up properly. I solve all the issues also. I get an sms also. But now I was facing a small problem. SMS is come Like this,

    mare tATZ
    AT+CREG?
    AT+CMGF=1AT+CMGS=”mobile number”
    Message

    Now the problem is that , I can not able to send only a message. AT commands also send along with that Message. And sometimes, It is not giving FULL sms. It is escaping some part of the SMS. What should I do?

    Thanks in advance….

    You did a great job.

    Please reply if you know.

  5. hi,
    Actually you post is very nice and helpfull..
    i am doing my project thst to send the sms from PC connected with mobile/gsm modem to another mobile….but when i run your code the messege not sending the output is..

    actionPerformed()
    Stable Library
    =========================================
    Native lib Version = RXTX-2.1-7
    Java lib Version = RXTX-2.1-7
    gnu.io.CommPortIdentifier@f3d6a5
    COM1: PORT_OWNED

    what will i do.can you help me

  6. HI ..

    Program is very good and running well..But , is there a way to send multiple recepients or a kind of a loop ..??

    Thanks..

  7. Hi
    Thank you . I have deployed this code into the eclipse. but can u please tel me what is COM Port number?

  8. Hello:
    First at all thanks a lot for your post. It is very useful. I have a problem. When run the program i not received any messages, but when i debug step by step the messages is sent. I think i due to some lost thread, i tried to solve it but i can´t. I hope someone can help. Thanks again,
    Regards, Jose

    • Hi Jose,

      can you please sent me your code, will look into it and let you know. I think its happening because of Comp port availability.
      Saurabh recently posted..Disable WhatsApps Blue Check Mark Message Read Confirmation My Profile

      • Hello Saraubh:
        Thanks for your replay. I am using the same code in the example. I found the problem is for the time for execution the AT command in the modem. The pc speed is more than fast than the execution in the modem. I solved it with Thread.sleep(500); in the sent method. But i am worried because I don´t know if this solution is not good when the traffic will be high.

        This is my code:

        public void send(String cmd) {
        try {
        outputStream.write(cmd.getBytes());
        Thread.sleep(500);
        } catch (IOException | InterruptedException e) {
        e.printStackTrace();
        }
        }

        Thanks again,
        Regards, Jose

  9. I have run the problem successfully but it says the rxtxserial.dll is not for 64 bit platform. do you have for 64 bit platform. i;m in rush because need to show to my lecturer the method. thank you

    • Hi James,
      Its versioning issue.

      the JVM you are running is 64-bit but the DLL rxtxSerial.dll is 32-bit. To resolve, either:

      Obtain 64-bit rxtxSerial.dll, or
      Install and use 32-bit JVM with the current rxtxSerial.dll

      If you have Java 7, then you need to put the files here for 64bit version:
      C:\Program Files\Java\jre7\bin\rxtxSerial.dll
      C:\Program Files\Java\jre7\lib\ext\RXTXComm.jar

      The 64-bit RXTX files are here:
      rxtxSerial.dll [http://goo.gl/sFoyfO]
      RXTXComm.jar [http://goo.gl/iCw53g]

      let me know if you need any help
      Saurabh recently posted..Disable WhatsApps Blue Check Mark Message Read Confirmation My Profile

  10. im Using 64bit Windows 8.1 this is not working its show 32bit error ?
    any help for 64bit ?

  11. Error is please help me

    run:
    actionPerformed()
    WARNING: RXTX Version mismatch
    Jar version = RXTX-2.2pre1
    native lib Version = RXTX-2.2pre2
    gnu.io.CommPortIdentifier@4b35caf9
    COM3: PORT_OWNED
    ATZ

    OK
    AT+CREG?

    • Please install latest java 1.7 64bit/32-bit version according to your machine.
      Let me know if you face any issue
      Saurabh recently posted..Current App Development Trends You Don’t want to MissMy Profile

      • i hav downloaded from official website java 1.7 new SE version but he still show actionPerformed()
        WARNING: RXTX Version mismatch
        Jar version = RXTX-2.2pre1
        native lib Version = RXTX-2.2pre2
        gnu.io.CommPortIdentifier@1c265af5
        COM3: PORT_OWNED
        ATZ

        OK

        Thanks for previous reply and thanks for next reply

        • HI Usman,

          goto http://rxtx.qbang.org/wiki/index.php/Download
          and download rxtx-2.1-7-bins-r2.zip from “Binary” column.
          goto C:\Users\Downloads\rxtx-2.1-7-bins-r2.zip\rxtx-2.1-7-bins-r2
          and copy RXTXcomm to
          C:\Program Files\processing-1.5.1\java\lib\ext
          goto C:\Users\Downloads\rxtx-2.1-7-bins-r2.zip\rxtx-2.1-7-bins-r2\Windows\i368-mingw32
          and copy both rxtxParallel.dll and rxtxSerial.dll to
          C:\Program Files\processing-1.5.1\java\bin

          This will help you. Let me know

      • can you please give me your facebook or twiter id please ..
        last night even i hav compatibility error my sms deliver successfully but now again
        at command ok but sending sms error
        thanks for reply
        im waiting

      • please help me..

        this is the error

        java.lang.UnsatisfiedLinkError: C:\Program Files (x86)\Java\jdk1.6.0_04\bin\rxtxSerial.dll: Can’t load AMD 64-bit .dll on a IA 32-bit platform thrown while loading gnu.io.RXTXCommDriver
        Exception in thread “AWT-EventQueue-0” java.lang.UnsatisfiedLinkError: C:\Program Files (x86)\Java\jdk1.6.0_04\bin\rxtxSerial.dll: Can’t load AMD 64-bit .dll on a IA 32-bit platform

  12. and this aplication not supported more then 150 char 🙁

  13. good day sir..just want to ask for any solution why it doesn’t work on my laptop..rxtxserial error..thanks

  14. Hello, i am using win 64bit, java 8 and newest rxtx library, using an Android mobile phone with its drivers via usb to make it act as a COM device and I get the following error:
    run:
    actionPerformed()
    gnu.io.CommPortIdentifier@5f8232b8
    gnu.io.CommPortIdentifier@270be6b1
    COM3: PORT_OWNED

    OK
    AT+CREG?
    +CREG: 0,1
    OK
    AT+CMGF=1
    OK
    AT+CMGS=”+37063931891″ // +370 being my country code, if i dont add country code i get the same error.
    +CMS ERROR: 330

    Any idea of what am I doing wrong and how to fix this error?
    Thank you.

  15. Sir everything working properly but sms not delivered i think send(message + ‘\032’); is not executing.

  16. hi , its work great but plz tell me how i catch the exception or any response if i put wrong cell no ?

    • Put some java-script validation in input field of MOBILE number.
      You can simply get it by googling, Have a look into this script
      http://goo.gl/ZfUpS

      • thanks for your reply but dear i am more concern about how to get the AT command response in a string as i try this way of getting response but some time its work but some time its not , i am unable to figure out the problem please help me in this regards , I shall be very thankful to you .
        public void send(String cmd) {
        try {
        outputStream.write(cmd.getBytes());
        BufferedReader reader = new BufferedReader(new InputStreamReader (serialPort.getInputStream()));
        String line = “”;
        line = reader.readLine();
        while (!line.equals(null)) {
        if (line.equalsIgnoreCase(“OK”) || (line.indexOf(“+CMGS”) != -1) || line.equalsIgnoreCase(“ERROR”)) {
        output = line;
        System.out.println(“—-command—“+cmd+”——output—-“+output);

        }
        line = reader.readLine();
        }
        }
        catch (Exception e) {
        }
        }

  17. The application send only one message, if someone wants to send a second one it says that it doesn’t initialise the card. Why?

    • Hi GEITSPR, you have to tweak code as and keep in loop to iterate or simply making daemon thread of same can help you. You are getting this msg coz ur retrying to use same instance. Let me know if you need any more help

  18. akhilesh shukla says:

    Hi Please Help Me i Didi all the suggestions in the comment bUt Not a single Success

    actionPerformed()
    Stable Library
    =========================================
    Native lib Version = RXTX-2.1-7
    Java lib Version = RXTX-2.1-7
    gnu.io.CommPortIdentifier@17984d4
    gnu.io.CommPortIdentifier@15dd901
    gnu.io.CommPortIdentifier@b8e1bb
    COM7: PORT_OWNED
    actionPerformed()
    gnu.io.CommPortIdentifier@1d7c25f
    gnu.io.CommPortIdentifier@13374d0
    gnu.io.CommPortIdentifier@1a514dd
    gnu.io.PortInUseException: Unknown Application
    at gnu.io.CommPortIdentifier.open(CommPortIdentifier.java:354)
    at sendMessage.Connect.connect(Connect.java:81)
    at sendMessage.GUIToSendMessage$2.actionPerformed(GUIToSendMessage.java:92)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$500(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

    • Hi Akhilesh, what error msg you are getting and what problem ur facing? Did u checked your port is configured properly ? Will surely troubleshoot your problem please provide more insights

Leave a Reply

Your email address will not be published. Required fields are marked *

CommentLuv badge