• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to Send SMS using Java Program  RSS feed

 
Constantine Mahesh
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Frndzzz,

Please let me know how to send sms to mobile using java programme.
i have tried lot of examples , i didn't get perfect example

Thank you in advance
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please beware of spellings like Frndzzz because many people cannot read it. Please tell us what you have tried, and also which tutorials you have found. We can't help until we know what is going wrong.
 
Constantine Mahesh
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Campbell Ritchie
i sms code in spring mvc

@RequestMapping(value="/sendsms")
public String doSendSMS(HttpServletRequest request,@ModelAttribute("screenMovieDetails") ScreenMovieDetails screenMovieDetails) {

String mobile_number = screenMovieDetails.getMobile_number();
String movie_title = screenMovieDetails.getMovie_title();
String screen_name = screenMovieDetails.getScreen_name();
String show_time = screenMovieDetails.getShow_time().toString();
String cinema_group = screenMovieDetails.getCinema_group_name();

System.out.println("url string....."+ mobile_number);
System.out.println("url string....."+ movie_title);
System.out.println("url string....."+ screen_name);
System.out.println("url string....."+ show_time);

try {

final TrustManager[] trustAllCerts = new TrustManager[] {
new X509TrustManager()
{
@Override
public void checkClientTrusted( final X509Certificate[] chain, final String authType ) {
}
@Override
public void checkServerTrusted( final X509Certificate[] chain, final String authType ) {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
} };



final SSLContext sslContext = SSLContext.getInstance( "SSL" );
sslContext.init( null, trustAllCerts, new java.security.SecureRandom() );

final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
HttpsURLConnection.setDefaultSSLSocketFactory( sslContext.getSocketFactory() );

String sendsms2 = "http://smsc.biz/httpapi/send?username=kodam.prince4@gmail.com&password=Kodammadhu4&sender_id=SMSIND&route=T&phonenumber="+mobile_number+"&message=Booking%20Details%20"+"%20THANK%20YOU%20FOR%20BOOKING%20TICKET%20WITH%20MTS%20MOVIE%20:"+movie_title
+"%20SCREEN%20NAME%20:"+screen_name+"%20THEATRE%20:"+cinema_group+"%20SHOW%20TIME%20:%20"+show_time;
URL url = new URL(sendsms2);

final HttpURLConnection conn = (HttpURLConnection) url.openConnection();

conn.setRequestMethod("GET");
int responseCode = conn.getResponseCode();
//System.out.println("Response Code : " + responseCode);
BufferedReader in = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();

while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
System.out.println(response.toString());

} catch (MalformedURLException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
}
System.out.println("sms sent successfully");

return "success";


}

In the above code string sendsms2 details are not sending to mobile sms details are updated in sms portal.

please do find the attached screen shoot for sms portal. in that screen shot red mark details are not going to received by mobile

pleae help me
sms.PNG
[Thumbnail for sms.PNG]
SMS protal screen shoot
 
Paul Clapham
Sheriff
Posts: 22838
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's a lot of irrelevant code there. And that's a problem for you as well as for us. you should write an ordinary Java application to test your SMS-sending code.

Anyway I think one problem is that you don't URL-escape the parameters in the HTTP URL.

And are those really your user ID and password you posted there? Not a good idea.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!