How to Send SMS through Java code in Windows

Updated on: January 12, 2019

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 ! 🙂

JAVA SMS SEND CODE Working
Post Tags: #java application to send sms #java sms send code #pc to mobile jsms java application #send sms without gateway #sms projects java
Amit
Amit is a Software Engineering & Android developer,who really want to share his Android tips & idea to android learner.Hope it will help you in future.Follow Him On

Leave a Reply

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

  1. 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.

      1. when i run this code it gives me error like unsuppported major.minor version 51. can you tell me why this problem occur and what i have to do for this ?

  2. 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.

  3. 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

    1. Hi Sruthi, can u please tell us which OS ur using,I mean 32-bit or 64-bit? Win xp or win7? A terminal issue may occur if you are using different lib. Your inputs will help us to solve your query

  4. HI ..

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

    Thanks..

  5. 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

      1. 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

  6. 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

    1. 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 [https://goo.gl/sFoyfO]
      RXTXComm.jar [https://goo.gl/iCw53g]

      let me know if you need any help

    1. Please install Java 1.7 64bit version and also include 64bit rxtxSerial.dll inside system32 folder.you can get it from google.
      I also suggest to refer previous comments of this thread.Many people face same issue and fixed.
      Let me know if it will not get resolved

    2. Install Java 1.7 64 bit version and include rxtxSerial.dll 64 bit DLL inside System32 folder,You can get it from Google easily.
      Even I recommended to refer previous comments for reference

  7. 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?

      1. 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

        1. HI Usman,

          goto
          and download rxtx-2.1-7-bins-r2.zip from "Binary" column.
          goto C:UsersDownloadsrxtx-2.1-7-bins-r2.ziprxtx-2.1-7-bins-r2
          and copy RXTXcomm to
          C:Program Filesprocessing-1.5.1javalibext
          goto C:UsersDownloadsrxtx-2.1-7-bins-r2.ziprxtx-2.1-7-bins-r2Windowsi368-mingw32
          and copy both rxtxParallel.dll and rxtxSerial.dll to
          C:Program Filesprocessing-1.5.1javabin

          This will help you. Let me know

      2. 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

      3. 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

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

  9. 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.

    1. HI look like you are getting CMS ERROR 330 which signifies 'SMSC address unknown' so I suggest remove + sign and enter your mobile number.

      This might help you. Let me know if ur issue will not get solved.

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

      1. 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) {
        }
        }

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

    1. 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

  12. 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)

    1. 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

  13. Hello,
    This code has been a huge help, but there also exists a problem. The output has the following:
    actionPerformed()
    Stable Library
    =========================================
    Native lib Version = RXTX-2.2pre2
    Java lib Version = RXTX-2.1-7
    WARNING: RXTX Version mismatch
    Jar version = RXTX-2.1-7
    native lib Version = RXTX-2.2pre2
    gnu.io.CommPortIdentifier@1e11ba0
    gnu.io.CommPortIdentifier@13361d1
    COM4: PORT_OWNED
    ATZ
    AT+OK
    AT+CMGS="**********"
    HI
    OK
    we did use a proper mobile number(the * is placed instead of a mobile number) but however we have not received any message so far. It would be considerate if you help us out.

  14. Hello,
    The output is the following:
    gnu.io.CommPortIdentifier@1e11ba0
    gnu.io.CommPortIdentifier@13361d1
    COM4: PORT_OWNED
    ATZ
    AT+
    OK
    AT+CMGS="8056288264"
    HI
    OK
    however we arent getting a sms. help us out.

0 Shares
Share via
Copy link