Enlightensoft's Blog

Helping in your each step

  • Categories

  • Authors

Archive for the ‘SMS’ Category

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………….”);

Posted in Core Java, SMS | 10 Comments »