Getting started with Kannel SMS Gateway

Prehistory


The authorities set the task of organizing SMS mailing for structural units of the organization. The sms distribution company provides the smpp protocol. It was necessary to organize the sending of short text messages via smpp, to receive delivery reports. Kannel was chosen as an SMS gateway.
The article is a “quick start” by Kannel and contains the basic settings of the gateway and code examples, based on which you can write your own SMS distribution system.
Installation and configuration will be illustrated by Fedora.

Remark


This article is not a clone of this http://habrahabr.ru/post/124302 and this http://habrahabr.ru/post/123380 articles.
I am familiar with them and used them during the work, mine and these articles will have much in common, but I wanted to somehow systematize all the information accumulated during the work for further use in the work.

Installation and setup


Install the package kannel:
yum install kannel
Create the user kannel
useradd kannel
Edit the file /etc/kannel.conf

group = core
admin-port = 13000
smsbox-port = 13001
admin-password = 1
log-file = "/var/log/kannel/kannel.log"
log-level = 0
dlr-storage = internal
store-file = "/home/kannel/kannel.store"
group = smsbox
bearerbox-host = "127.0.0.1"
sendsms-port = 13003
group = sendsms-user
username = foo
password = bar
concatenation = true
max-messages = 20
group = smsc
smsc = smpp
smsc-id = id
host = domain.com
port = 3700
transceiver-mode = 1
smsc-username = "login"
smsc-password = "password"
system-type = "VMA"
address-range = ""
log-file = "/var/log/kannel/smsc-operator.log"
log-level = 0


We start kannel
/etc/init.d/kannel start

In order to make sure that everything works, go to the address:
mydomain.com:13000/status

SMS sending


In order to send SMS in the simplest case, you need to type in the address bar:
domain.com:13003/cgi-bin/sendsms?user=foo&pass=bar&from=Test&coding=0&to=38050000000000&text=Test1
This technique can be used for the test, but in real life it is not suitable. Yes, and I want to send SMS not in transliteration, but in Russian. In this case, the following code will do:
function send_sms($from, $to, $mytext)
{
$mytext=urlencode(iconv("utf-8","ucs-2be",$mytext));
$url = "http://domain.com:13003/cgi-bin/sendsms?user=foo&pass=bar&from=$from&coding=2&to=$to&text=$mytext";
file_get_contents($url);    
}


If you want to send in transliteration (or just completely in English), then there is no need to transcode the text and the parameter coding = 0 is used in the address bar.
function send_sms_translit ($from, $to, $mytext)
{
$mytext=urlencode($mytext);
$url = "http://domain.com:13003/cgi-bin/sendsms?user=foo&pass=bar&from=$from&coding=0&to=$to&text=$mytext";
file_get_contents($url);    
}

It is worth noting that long sms of such images are sent correctly, absolutely no problems arise.

Delivery Reports


To receive delivery reports, we need to assign the id of each SMS and send Kannel the address that he should call when receiving a delivery report.
First, I’ll give a code
function send_sms($from, $to, $mytext, $smd_id)
{
$mytext=urlencode(iconv("utf-8","ucs-2be",$mytext));
$dlrurl=urlencode("http://domain.com/smsdeliv.php?smsid=$sms_id&type=%d");
$url = "http://domain.com:13003/cgi-bin/sendsms?user=foo&pass=bar&from=$from&coding=2&to=$to&dlr-mask=1&dlr-url=$dlrurl&text=$mytext";
file_get_contents($url);
}

In the parameter, dlr-url we pass the address that will be called when the delivery report is received.
The parameter dlr-maskdetermines which types of delivery messages we want to receive.
The mechanism of operation of this scheme is described in
detail at www.kannel.org/download/kannel-userguide-snapshot/userguide.html#DELIVERY-REPORTS .
The types of delivery messages and their numerical values ​​are also shown there.
I do not see the point of bringing them here additionally.
That's all, thanks for your attention.

Also popular now: