Enlightensoft's Blog

Helping in your each step

  • Categories

  • Authors

  • Advertisements

Send SMS usign SMS Getway in JAVA

Posted by Pankil Patel on April 7, 2010

How to send SMS with java code using SMS getway?

Required Jars:


package com.es.sms.one;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

* Class to help send SMS messages
* @author Pankil Patel
public class SmsHelper {
private static final Log logger = LogFactory.getLog(SmsHelper.class);

private static final String PARAM_USER = “uname”;

private static final String PARAM_PASSWORD = “pword”;

private static final String PARAM_MESSAGE = “message”;

private static final String PARAM_SENDER = “from”;

private static final String PARAM_PHONE_NO = “selectednums”;

private static final String PARAM_INFO = “info”;

* Send an SMS message via the gateway. Returns whether or not the message
* could be successfully sent.
* @param sender
* @param phoneNumber
* @param smsText
* @return
public static boolean sendSMS_Live(final String sender,
final String phoneNumber, final String smsText) {
try {
final HttpClient client = new HttpClient();

final HttpMethod method = new GetMethod(

method.setQueryString(new NameValuePair[] {
new NameValuePair(PARAM_USER,
new NameValuePair(PARAM_MESSAGE, smsText),
new NameValuePair(PARAM_SENDER, sender),
new NameValuePair(PARAM_PHONE_NO, phoneNumber),
new NameValuePair(PARAM_INFO, “1”), });

final int statusCode = client.executeMethod(method);
.debug(“SmsHelper: QueryString>>> ”
+ method.getQueryString());
logger.info(“SmsHelper: Status Text>>>”
+ HttpStatus.getStatusText(statusCode));
return true;
} catch (final Exception e) {
logger.error(“Exception sending SMS: ” + e.toString());
return false;
Main Class to run:
package com.es.sms.one;


public class Test {
public static void main(String[] args) {
SmsHelper.sendSMS_Live(“Pankil Patel”, “+919725006017”, “Hi………….”);


10 Responses to “Send SMS usign SMS Getway in JAVA”

  1. admin said

    hiiii….through this i am trying to send code…..there isn’t any error…and it gives messages that succesfully sent…
    but on mobile there isn’t any message come….
    i had try as u above mention….
    so what to do next????

  2. prabhu said

    hi please explain your code step by step. i have many error in your code.

  3. sharu said

    hi i tried to send sms to mobile using above code.
    the program is working fine without any errors. but the mobile is not getting any sms.
    i have username and pwd from http://www.txtlocal.co.uk/ but not sending sms to mobile
    can u help me

  4. Hey I tried to this work but I couldn’t could any of you please send me the working code.

  5. vaibhav said

    pls send code for send sms in struts2 and how to run the above code

  6. I am really enjoying the theme/design of your website.
    Do you ever run into any web browser compatibility issues?
    A handful of my blog readers have complained about my blog not
    operating correctly in Explorer but looks great in Firefox.
    Do you have any ideas to help fix this problem?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: