Thursday, May 7, 2009

SMS sending through WEB application

Send and Receive SMS through Web Application

There are two ways to achieve this
1. By using mobile (GSM) device connected to pc.
2. By using SMS gateway provider(http://www.developershome.com/sms/sms_tutorial.asp?page=smsGateway).


Using sms gateway provider

how to select the sms gateway provider

http://www.developershome.com/sms/howToChooseSMSGateway.asp

e.g of sms gateway provider
1.https://www.clickatell.com/
2.http://www.textmarks.com/dev/docs/recv/?ref=devsb

There needs an api which connects the web application to the sms gateway provider. The api is depdends upon the gateway provider.

The sms is sended/ received to/from the gateway provider by diffrent method
such as,
http, smpp, xml, smtp. that are used by the api.
e.g.
https://www.clickatell.com/developers/api_http.php

For demo of sending sms register and provider they provide an api to connect with them to send sms

Following is java prog to test sms sending using clickatell as provider

the prog use smsj.jar and slf4j-api-1.3.1.jar

import org.marre.SmsSender;
import org.marre.sms.SmsMessage;
import org.marre.sms.SmsPdu;


public class smsSend {

public static void main(String args[]){
try
{
// Send SMS with clickatell
SmsSender smsSender = SmsSender.getClickatellSender("username", "passwd", "sys_id");
String msg = "A sample SMS.";
// International number to reciever without leading "+"
String reciever = "98*********";
// Number of sender (not supported on all transports)
String sender = "98******";
// Connect
smsSender.connect();
smsSender.disconnect();

}catch(Exception e){
System.out.println("the Exception is ====="+e);

}
}
}
*************************************************
Using gsm connected(Mobile Device) to pc to send and receive sms


Can be done by using kannel as intermediator.


**************************************************

Using Kannel (Sms gateway ) to send and receive sms by SMS service provider and gsm modem connected to system.

You can install kannel by two ways

1. By using

sudo apt-get install kannel

2. And in second method by downloading the tar.gz and compiling it.


Step 1 - Satisfying requirements / dependencies for kannel


Build dependencies:

Install build tools (gcc, mac, g++, etc. Not all necessary but you should have them!)

* sudo apt-get install build-essential

Install required Kannel dependencies (there are obviously way more, but this is all required on Kubuntu 8.04)

* sudo apt-get install libxml2-dev

Install optional Kannel dependencies (These are only required if you would like to use SSL enabled servers, alternate DLR storage options etc. For the purposes of this example I will enable our Kannel build for SSL and PostgreSQL DLR storage)

* sudo apt-get install openssl-dev
* sudo apt-get install libpq-dev

Step 2 - Getting the source of Kannel.

Option a) Downloading latest stable

Visit the kannel download page and download the source as gzip tarball (or bzip2 tarball if you prefer). In the directory you downloaded execute:

I chose to install to /usr/local/kannel

# mkdir src
# cd src
# tar xfz ../downloads/gateway-1.4.1.tar.gz
# cd gateway-1.4.1

Step 3 - Building Kannel

Change directory to the directory you downloaded the source to (gateway-X.X.X or gateway-cvs)

Execute:

* ./configure

This should configure the build correctly with OpenSSL and PostgreSQL support.

if make is not install then install it by using

* sudo apt-get install make

Once that’s done, execute:

* make

This will build the binaries for Kannel, if you want to install them system wide at this point you can by executing:

* sudo make install

Step 4--

using kannel -----

to start---
sudo /etc/init.d/kannel start

then fire these in diffrent terminal/tab
sudo gw/bearerbox gw/smskannel.conf

sudo gw/smsbox gw/smskannel.conf


Reference Site--
--> installation of kannel
http://www.ddj.co.za/archives/46/howto-compile-kannel-on-ubuntukubuntu-804

--> how to configure the kannel
http://www.chipmunkninja.com/Setting-up-Configuring-and-Using-13@

--> kannel configuration to send and receive using sms provider(Clickatell)

smskannel.conf

group = core
admin-port = 13009
smsbox-port = 13001
admin-password = bar
box-deny-ip = "*.*.*.*"
box-allow-ip = "127.0.0.1"

group = smsc
smsc = http
smsc-id = click
system-id = click_tell_system_id(1234)
system-type = clickatell
smsc-username = clickatell_username
smsc-password = clickatell_passwd
send-url = "http://api.clickatell.com/http/sendmsg"
port = 13015
allowed-smsc-id = click
connect-allow-ip = 127.0.0.1

group = smsbox
bearerbox-host = 127.0.0.1
sendsms-port = 13013
global-sender = 13013


group = sendsms-user
username = uname(uname and password that you will be used for sending sms)
password = xxxxx
user-deny-ip = "*.*.*.*"
user-allow-ip = "127.0.0.1"
max-messages = 2
default-smsc = click

--> kannel configuration with mobile device connected to pc
I tried this with ubuntu and nokia 6080
(Note: there were problem while receiving sms in higer version of nokia)

before going to smskannel.conf

connected the mobile to USB port

check at which port it get connected by using
tail /var/log/message/
( May it connect at /dev/ttyxxx)
The device port will be used in conf file

smskannel.conf

group = smsc
smsc = at
modemtype = AT2
device = /dev/ttyUSB0
#device = /dev/ttyACM0
speed = 0
smsc-id = Nokia_smsc
port = 13131
log-level = 0

group = modems
id = AT2
name = "Nokia 6080 config"
detect-string="Nokia"
detect-string2="Nokia 6080"
init-string = "AT+CNMI=1,2,0,1,0"
speed = 19200

group = sms-service
keyword = default
text = "Accessing default services"
send-sender = true

--> Kannel with Teltonika modem

group = smsc
smsc = at
smsc-id = "INNER"
modemtype = teltonika
device = /dev/ttyS0
#device = /dev/ttyUSB0
#device = /dev/ttyACM0
speed = 0
port = 13131
log-level = 0
sim-buffering = true

# cofiguration for teltonika modem g10(COM)

group = modems
id = teltonika
name = "Teltonika G10"
detect-string = "Undefined"
enable-mms = true
init-string = "AT+CNMI=2,2,0,1,1"
speed = 115200
message-storage = "SM"

Running kannel--------------------

--> to start---
/etc/init.d/kannel start

--> then fire these in diffrent terminal/tab
gw/bearerbox gw/smskannel.conf
gw/smsbox gw/smskannel.conf

---> send sms by both ways
http://localhost:13013/cgi-bin/sendsms?username=username&password=passwd&to=to_no&text=helloworld&coding=2&charset=iso-8859-7
(Note:- username and password that given in smskannel.conf)

--> Connect java prog with kannel
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package com.myapp.struts.window;

/**
*
* @author chetan
*/
public class sendSmsByKannel {

//public String send(String serverIP, String serverSendPort, String user, String password, String smsc, String mt, String text, String from) {
public String send(String serverIP, String serverSendPort, String user, String password, String toNO, String text, String from) {
String result = "";
try {
String data = java.net.URLEncoder.encode(text, "UTF8");
String msisdn = java.net.URLEncoder.encode(toNO, "UTF8");
String sendURL = "http://" + serverIP + ":" + serverSendPort + "/cgi-bin/sendsms?username=" + user + "&password=" + password + "&charset=utf-8&coding=2&to=" + msisdn + "&text=" + data ;// "&smsc=" + smsc+ "&from=" + from;

java.net.URL url = new java.net.URL(sendURL);
java.io.InputStream in = url.openStream();
java.io.BufferedInputStream bufIn = new java.io.BufferedInputStream(in);
for (;;) {
int car = bufIn.read(); // Check for EOF
if (car == -1) {
break;
} else {
result = result + (char) car;
}
}
bufIn.close();
in.close();

} catch (Exception e) {
e.printStackTrace();
}

return result;
}

public static void main(String args[]){
sendSmsByKannel ssk=new sendSmsByKannel();
ssk.send(localhost, 13013, user, password, toNO, text, from) {

System.out.println("Message sened succesfully");

}

}

That's it !___________________
¢нeтαη Menge