1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14.

Saturday, May 9, 2009

send SMS using u'y wey2sms account (Java)

This program help you to send sms using way2sms account

Its not written by by me I have just modified it


smsconfig.properties
user=way2sms username
password=way2sms password
proxy_enabled=true/false
proxy_host=if true ip of the proxy
proxy_port=port number of proxy
protocol=http

/**
* SMSConfig.java
* Created on Mar 11, 2009 6:36:23 AM
*/
package sms;

import java.util.ResourceBundle;

/**
* @author Nimish T
*
*/
public class SMSConfig {

/**
*
*/
public SMSConfig() {
// TODO Auto-generated constructor stub
}
private static ResourceBundle resourceBundle;
public static String USERNAME;
public static String PASSWORD;
public static boolean PROXY;
public static String PROXY_HOST;
public static int PROXY_PORT;
public static String PROTOCOL;
static {
try {
resourceBundle=ResourceBundle.getBundle("sms.smsconfig");
init();
} catch (Exception e) {
//e.getMessage();
e.printStackTrace();
}
}
private static void init(){
USERNAME=resourceBundle.getString("user");
PASSWORD=resourceBundle.getString("password");
PROXY=Boolean.valueOf(resourceBundle.getString("proxy_enabled"));
if(PROXY){
PROXY_HOST=resourceBundle.getString("proxy_host");
PROXY_PORT=Integer.parseInt(resourceBundle.getString("proxy_port"));
PROTOCOL=resourceBundle.getString("protocol");
}

}
}



/**
* SMS.java
* Created on Mar 10, 2009 7:37:35 PM
*/
package sms;

/**
* @author Nimish T
*
*/

import java.io.*;
import java.net.*;
import java.util.Vector;

public class SMS
{
public static void send(String uid, String pwd, String phone, String msg) throws IOException {

if (uid == null || 0 == uid.length())
throw new IllegalArgumentException("User ID should be present.");
else
uid = URLEncoder.encode(uid, "UTF-8");

if (pwd == null || 0 == pwd.length())
throw new IllegalArgumentException("Password should be present.");
else
pwd = URLEncoder.encode(pwd, "UTF-8");

if (phone == null || 0 == phone.length())
throw new IllegalArgumentException("At least one phone number should be present.");

if (msg == null || 0 == msg.length())
throw new IllegalArgumentException("SMS message should be present.");
else
msg = URLEncoder.encode(msg, "UTF-8");

Vector numbers = new Vector();
String pharr[];
if (phone.indexOf(';') >= 0) {
pharr = phone.split(";");
for (String t : pharr) {
try
{
numbers.add(Long.valueOf(t));
}
catch (NumberFormatException ex)
{
throw new IllegalArgumentException("Give proper phone numbers.");
}
}
} else {
try
{
numbers.add(Long.valueOf(phone));
}
catch (NumberFormatException ex)
{
throw new IllegalArgumentException("Give proper phone numbers.");
}
}

if (0 == numbers.size())
throw new IllegalArgumentException("At least one proper phone number should be present to send SMS.");

/*==================================================================*/

// Login
String temp = "";
String content = "username=" + uid + "&password=" + pwd + "&q=Deepika%20Padukone%20Photo%20Gallery";
URL u=null;
if(SMSConfig.PROXY){
u = new URL(SMSConfig.PROTOCOL,SMSConfig.PROXY_HOST,SMSConfig.PROXY_PORT,"http://wwwd.way2sms.com/auth.cl");
} else {
u = new URL("http://wwwd.way2sms.com/auth.cl");
}
HttpURLConnection uc = (HttpURLConnection) u.openConnection();
uc.setDoOutput(true);
uc.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5");
uc.setRequestProperty("Content-Length", String.valueOf(content.length()));
uc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
uc.setRequestProperty("Accept", "*/*");
uc.setRequestMethod("POST");
uc.setInstanceFollowRedirects(false); // very important line :)
PrintWriter pw = new PrintWriter(new OutputStreamWriter(uc.getOutputStream()), true);
pw.print(content);
pw.flush();
pw.close();
BufferedReader br = new BufferedReader(new InputStreamReader(uc.getInputStream()));
while ( (temp = br.readLine()) != null ) {}
String cookie = uc.getHeaderField("Set-Cookie");

// Send SMS to each of the phone numbers
u = null; uc = null;
for (long num : numbers)
{
content = "HiddenAction=instantsms&login=&pass=&custid=undefined&MobNo=" + num + "&textArea=" + msg;
if(SMSConfig.PROXY){
u = new URL(SMSConfig.PROTOCOL,SMSConfig.PROXY_HOST,SMSConfig.PROXY_PORT,"http://wwwd.way2sms.com/FirstServletsms?custid=");
} else {
u = new URL("http://wwwd.way2sms.com/FirstServletsms?custid=");
}
uc = (HttpURLConnection) u.openConnection();
uc.setDoOutput(true);
uc.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5");
uc.setRequestProperty("Content-Length", String.valueOf(content.length()));
uc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
uc.setRequestProperty("Accept", "*/*");
uc.setRequestProperty("Cookie", cookie);
uc.setRequestMethod("POST");
uc.setInstanceFollowRedirects(false);
pw = new PrintWriter(new OutputStreamWriter(uc.getOutputStream()), true);
pw.print(content);
pw.flush();
pw.close();
br = new BufferedReader(new InputStreamReader(uc.getInputStream()));
while ( (temp = br.readLine()) != null ) {}
br.close();
u = null;
uc = null;
}

// Logout
if(SMSConfig.PROXY){
u = new URL(SMSConfig.PROTOCOL,SMSConfig.PROXY_HOST,SMSConfig.PROXY_PORT,"http://wwwd.way2sms.com/jsp/logout.jsp");
} else {
u = new URL("http://wwwd.way2sms.com/jsp/logout.jsp");
}
uc = (HttpURLConnection) u.openConnection();
uc.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5");
uc.setRequestProperty("Accept", "*/*");
uc.setRequestProperty("Cookie", cookie);
uc.setRequestMethod("GET");
uc.setInstanceFollowRedirects(false);
br = new BufferedReader(new InputStreamReader(uc.getInputStream()));
while ( (temp = br.readLine()) != null ) {}
br.close();
u = null;
uc = null;
}
}


//Mail send example
public class SMSSender{
public static void main(String a[]){
SMS.send(SMSConfig.USERNAME, SMSConfig.PASSWORD, "9496340776", "My First SMS");
}
}



cellphone application developers cochin kerala
website hosting development kochi kerala

37 comments:

  1. how To Develop This Code Please Guide Me

    ReplyDelete
  2. Thanks to you buddy.......... :)

    chindukrishna@gmail.com

    ReplyDelete
  3. Thanks it works...!

    ReplyDelete
  4. Thank you very much, this code will help many users and it helped me too................

    ReplyDelete
  5. Hi, when i implement this code, with our office LAN (Proxy) settings, while executing this code this is giving Server returned HTTP response code: 403 for URL: http://wwwd.way2sms.com/auth.cl error. However this is nice work from u.

    ReplyDelete
  6. Thanks buddy, it is really nice. I have one query regarding this, can we omit the succeeded part (By Way2SMS.com stuff) from message after receiving to end user, and instead of from telephone number can we display any String which is configurable.

    Thanks in Advance.

    ReplyDelete
  7. i am getting a error for incompitable types for the line
    for(long num : numbers){}

    please help me

    ReplyDelete
  8. Hi In my machine the code has no error it runs with no issue still i am able to send sms. I am using mac OS. Can any one help me to fix the issue.

    My email id is -: naresh_sahoo1981@yahoo.com
    Thanks,
    Naresh

    ReplyDelete
  9. @Anonymous Hey change the declaration, of

    Vector numbers = new Vector();

    to this:

    Vector<Long> numbers = new Vector<Long>();

    Now, it will work :)

    ReplyDelete
  10. Hi, when i implement this code ,while executing this code this is giving Server returned HTTP response code: 500 for URL: http://wwwd.way2sms.com/auth.cl error.
    plz hlp me solve ths prob.
    However this is verynice work from u.

    ReplyDelete
  11. even i m getting the java.io.IOException: Server returned HTTP response code: 500 for URL: http://wwwd.way2sms.com/auth.cl

    please Help...

    ReplyDelete
  12. how to implement this code.pls help me..how is the link between smsconfig.java and sms.java...

    ReplyDelete
  13. i am also getting the error:
    Server returned HTTP response code:500 for URL
    http://wwwd.way2sms.com/auth.cl
    pls help me too.....
    my mail id:sharanbabu@yahoo.co.in
    kindly mail me....
    infact i have used my registered userid and password only.

    ReplyDelete
  14. even im facing the same problem http:500 and any one can help me plz with the source code for sms sending using java pplzz frnds

    ReplyDelete
  15. Looks like there have been some changes from Way2SMS website in the URLs.
    I changed the auth url to
    www2.way2sms.com/auth.cl
    I could get around the 500 exception.
    but then I get error 400 when the SMS is being posted. I tried modifying the header for the second post request. But nothing seemed to work.
    Any ideas anyone ?

    ReplyDelete
  16. Hi all.. I am getting the error of

    java.net.UnknownHostException: wwwd.way2sms.com

    at line
    pw = new PrintWriter(new OutputStreamWriter(uc.getOutputStream()), true);

    Please help urgently..

    ReplyDelete
  17. i hv build the code but the message is not bieng recieved ..plzz send me the code at naman.bbps@gmail.com

    ReplyDelete
  18. Now it is not working

    ReplyDelete
  19. can anyone give me steps how to develop this code

    ReplyDelete
  20. can anyone give me steps for working this code
    this is my email address "hydroxy.lesnar@gmail.com"

    ReplyDelete
  21. hi can you help me to understand the steps involved using this code. i need to add it in my project work please help me

    ReplyDelete
  22. code is explained in our new site
    http://www.codeglobe.in

    ReplyDelete
  23. hi this is my mail id can you help me in detail to use the code. i need to include it in my project. this is my mail id is annisetty@gmail.com

    ReplyDelete
  24. function sendsms($mobile, $text){
    $username="ur no.";
    $password="freeeesms";
    $result = "";
    $headers= "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.14) Gecko/2009082707 Firefox/3.0.14\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\nAccept-Language: en-us,en;q=0.5\nAccept-Encoding: gzip,deflate\nAccept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\nKeep-Alive: 300\nConnection: keep-alive\n";
    $fp = fsockopen("way2sms.com", 80, $errno, $errstr, 30);
    if($fp){
    $request="GET / HTTP/1.1\nHost: way2sms.com\n$headers\n";
    fputs($fp, $request);

    //echo "Request:
    ".$request;

    while(!feof($fp)){
    $result .= fgets($fp, 128);
    }
    fclose($fp);

    //echo "

    Reply:
    ".$result;

    }
    $return=explode("\n", $result);
    $return=$return[3];
    $i=17;
    $location="";
    while($return[$i]!="/"){
    $location.=$return[$i];
    $i++;
    }

    $fp1 = fsockopen($location, 80, $errno, $errstr, 30);
    if($fp1){
    $request="POST /auth.cl HTTP/1.1\nHost: $location\n$headers"."Referer: http://$location/content/prehome.jsp\nContent-Type: application/x-www-form-urlencoded\nContent-Length: 43\n\nusername=$username&password=$password";
    fputs($fp1, $request);

    //echo "

    Request:
    ".$request;

    while(!feof($fp1)){
    $result1 .= fgets($fp1, 128);
    }
    fclose($fp1);

    //echo "

    Reply:
    ".$result1;

    }
    $blah=strstr($result1, "Location: ");
    $return=explode("\n", $blah);
    $return1=$return[0];
    $return="";
    $blah="";
    $blah=strstr($result1, "Set-Cookie: ");
    $return=explode("\n", $blah);
    $blah="";
    $return=$return[0];
    $return=explode(" ", $return);
    $return=$return[1];
    $return=explode(";", $return);
    $cookie=$return[0];
    $blah=explode(".com", $return1);
    $blah=$blah[1];
    $blah=explode("Main.jsp", $blah);
    $blah=$blah[0];
    $blah=explode("jsp/", $blah);
    $blah=$blah[0];
    $fp2=fsockopen($location, 80, $errno, $errstr, 30);
    $data="custid=undefined&HiddenAction=instantsms&Action=custfrom1000000&MobNo=$mobile&textArea=".urlencode($text)."&yincheck=on";
    if($fp2){
    $request="POST $blah"."FirstServletsms?custid= HTTP/1.1\nHost: $location\n$headers"."Referer: http://$location//jsp/InstantSMS.jsp?val=0\nContent-Type: application/x-www-form-urlencoded\nCookie: $cookie\nContent-Length: ".strlen($data)."\n\n$data";
    //$request="POST //FirstServletsms?custid= HTTP/1.1\nHost: $location\n$headers"."Referer: http://$location//jsp/InstantSMS.jsp?val=0\nContent-Type: application/x-www-form-urlencoded\nCookie: $cookie\nContent-Length: ".strlen($data)."\n\n$data";
    fputs($fp2, $request);

    //echo "

    Request:
    ".$request;

    while(!feof($fp2)){
    $result2 .= fgets($fp2, 128);
    }
    fclose($fp2);

    //echo "

    Reply:
    ".$result2;

    }
    if(substr_count($result2, "OK")){
    return true;
    }
    else return false;
    }


    ?>


    check this and help me why its no working /....mail me....working url admin@livechat-wap.net

    ReplyDelete
  25. hi,
    how to this code is work ,guide me
    sandeep.bahare@gmail.com

    ReplyDelete
  26. Hi ,
    Please help me find out how do i use way2sms and java to send sms .

    Please help

    ReplyDelete
  27. hi it shows error like this

    java.util.MissingResourceException: Can't find bundle for base name sms.smsconfig, locale en_US
    at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1427)
    at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1250)
    at java.util.ResourceBundle.getBundle(ResourceBundle.java:705)
    at install.SMSConfig.(SMSConfig.java:30)
    at install.SMSSender.main(SMSSender.java:14)
    Exception in thread "main" java.lang.IllegalArgumentException: User ID should be present.
    at install.SMS.send(SMS.java:22)
    at install.SMSSender.main(SMSSender.java:14)
    Java Result: 1

    ReplyDelete
  28. hi all,

    I getting error like this

    java.util.MissingResourceException: Can't find bundle for base name sms.smsconfig, locale en_US
    at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1427)
    at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1250)
    at java.util.ResourceBundle.getBundle(ResourceBundle.java:705)
    at install.SMSConfig.(SMSConfig.java:30)
    at install.SMSSender.main(SMSSender.java:14)
    Exception in thread "main" java.lang.IllegalArgumentException: User ID should be present.
    at install.SMS.send(SMS.java:22)
    at install.SMSSender.main(SMSSender.java:14)
    Java Result: 1

    ReplyDelete
  29. hi

    I am getting error like this

    java.util.MissingResourceException: Can't find bundle for base name sms.smsconfig, locale en_US
    at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1427)
    at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1250)
    at java.util.ResourceBundle.getBundle(ResourceBundle.java:705)
    at install.SMSConfig.(SMSConfig.java:30)
    at install.SMSSender.main(SMSSender.java:14)
    Exception in thread "main" java.lang.IllegalArgumentException: User ID should be present.
    at install.SMS.send(SMS.java:22)
    at install.SMSSender.main(SMSSender.java:14)
    Java Result: 1

    ReplyDelete
  30. Hi, I am getting following exception while executing program, any idea why??

    java.io.IOException: Server returned HTTP response code: 503 for URL:

    ReplyDelete
  31. The program runs however sms would not get delivered.

    ReplyDelete

Related Posts with Thumbnails