How to Send Free SMS From java using SMS API?
As you all know guyz, the era that we are living is an era of internet, so everyone is hanging on their PC all the time. Everyday we are sending some SMS to our friends in order to inform something to them. So, if there is some method that can send SMS for free, everyone gonna use that method and loved it. Today, in this tutorial we are gonna discuss about that method but we are gonna send that message using our own program (java). And also if you wanna send the message to your friends without displaying your number and name, this tutorial is for you! sometime we are in the mode of cracking jokes and wanna fool your friends or sending some threatening message(only for entertainment purpose otherwise it will be illegal) you can use this method.
“This tutorial may be very useful for those who want to integrate SMS features in their project which is developed in java”.
For sending SMS using SMS API approach: you have to do two task:
1. Selecting Carrier
2. Writing java code
we are selecting txtlocal as our carrier. So, All you have do is go to http://www.txtlocal.co.uk and there you need to create one account. after creating account. (you need to fill up some of your information and txtlocal will send you a verification email into your email and verify your account [watch the video for detail]). After completing this step, go http://api.txtlocal.com/docs/sendsms and from the select language option choose java and then copy the code and edit as in the following manner or simply copy the following code but you need to provide your own api key when you run this project.
After doing this, you complete the task of selecting your carrier. Now write the following piece of code after designing the following form in NetBeans IDE.
In order to design this form follow the following procedure:
[sociallocker]
1. Now open Netbeans IDE and click on file > new project. Select categories as java and project as java application from that window:
2. Click next and then give your project name and then click finished.
3. Now right click on your project and select new > JFrame Form:
4. After this new window will appear from this window drag Panel and extend it, and drag four label, three Text Field, one text area and one Button and drop to the jframe form.
5. Change the properties of each elements by right clicking and give the suitable variable name to each text field, text area and button and change the name of each label and button to suitable name like, api key, send etc.
6. Double click in the send button to go to the source code section of the program and write the following piece of code.
a. Import the following packages at the beginning of the program.
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.URL; import java.net.URLConnection; import java.net.URLEncoder; import java.net.HttpURLConnection;
b. Inside the clicking event of button write the following code.
try { // Construct data String apiKey = "apikey=" + txtapi.getText(); String message = "&message=" + txtmess.getText(); String sender = "&sender=" + txtsender.getText(); String numbers = "&numbers=" + txtnumber.getText(); // Send data HttpURLConnection conn = (HttpURLConnection) new URL("https://api.txtlocal.com/send/?").openConnection(); String data = apiKey + numbers + message + sender; conn.setDoOutput(true); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Length", Integer.toString(data.length())); conn.getOutputStream().write(data.getBytes("UTF-8")); final BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); final StringBuffer stringBuffer = new StringBuffer(); String line; while ((line = rd.readLine()) != null) { //stringBuffer.append(line); JOptionPane.showMessageDialog(null, "message"+line); } rd.close(); //return stringBuffer.toString(); } catch (Exception e) { //System.out.println("Error SMS "+e); JOptionPane.showMessageDialog(null, e); //return "Error "+e;
7. To run this program you need to right click on your jframe and click run file as below:
8.Now Login to the your txtlocal account, goto setting>API KEY and then click on create API Key and then simply copy that created key.
9. Run your project by clicking in that play button. Input your API Key, Sender Name, Phone number with country code in the respective textbox and then click on Send button.
That’s it guyz. if you want to send free SMS using email2sms mething in java here is the tutorial: CLICK HERE
May be after sending 10 SMS your credit will be finished! but don’t be sad you can send more and more SMS but you need to create another account with another email account in www.txtlocal.co.uk ! that’s it. you may not be that much happy to hear this (sending only 10 SMS) but don’t forget you are able to send these 10 SMS for free and also there is one line “To get something, you must lose something”. it means you have to spend some time in creating account in txtlocal.co.uk in order to send free SMS.
[/sociallocker]
Finally, if you guyz think, this is awesome tutorial and help you in some extend please share this tutorials with your all friend so that they can know about this method of sending SMS!
watch the video: