Sending SMS with SMPP, Kannel and Java

By admin | July 17, 2016 | No Comments

Sending SMS with SMPP, Kannel and Java

There are many technologies and protocols that can be used to send and receive SMS from an application. This article focuses on sending SMS via a Short Message Service Center (SMSC), with the help of the Kannel SMS gateway.In order for an application to send a SMS, it generally has to communicate with a Mobile Network Operator (MNO) over the Internet. To understand in more detail consider the following example.A Media service provider wants to send a program timetable as an SMS to its end customers. The application is running on a Linux based java application server. One of the main requirements is to send an SMS through an SMSC, and this SMSC service is provided by one of the mobile network operators.
Before diving deeper into the subject, let’s go through some of the technical jargon.SMSC: stands for the Short Message Service Center and is part of the telecommunications network to deliver the SMS. It enables the external application to integrate via the Internet.SMPP: stands for the Short Message Peer-to-Peer (SMPP) and it’s a protocol which is used to exchange the SMS between SMSC and external entities like business applications.There are various versions of SMPP, including 3.3, 3.4 and 5.0. In this article version 3.4 is used. (Means the SMSC supports the version 3.4, more details from
Kannel SMS gateway it is an open source WAP and SMS gateway used to provide short message service (SMS). Currently it runs on the Linux platform and provides a high level HTTP service for submitting SMS requests. It supports many protocols to connect with the SMSC and even supports the GSM modem. (For more details
Now back to our example

This media service provider wants to connect with the SMSC by using the SMPP protocol. Implementing the protocol takes some time, so why reinvent the wheel? Therefore the service provider plans to use the Kannel SMS gateway to connect with the SMSC. At the development phase it is important to test the SMSC integration, but most of the time it won’t be possible to test with the production SMSC and of course each SMS is an added cost. Therefore to test the integration an SMPP SMSC simulator will be used. From it’s possible to download a free simulator. This simulator is a Java application and by default it will be running on port 2775. It is configurable from the property file SMPPSim/conf/smppsim.props.

Setting up the Kannel Server

Let’s now look into setting up the Kannel Server. Kannel is deployed on Linux systems (at the moment Windows platform is not supported; possibly using a virtual machine it could be run under Windows). Please be sure to include mysql support (or any other database support) when compiling the Kannel. It will be used to store the intermediate message between Kannel and SMSC specially the SMS delivery receipts.

Let’s assume, Kannel is deployed in /usr/local/kannel. Actually Kannel is a composed of 3 main components which are bearerbox, smsbox and wapbox. To run the Kannel, following 2 components must be started in a sequence.

First bearerbox should be started then smsbox should be started.

Both these boxes need a configuration file which contains the setting details. We’ll look into a sample configuration file (mytestkannel.conf). (More details can be retrieved from the Kannel documentation/user guide). This configuration file will have multiple sections; let’s go through the first section.

1. Configuring the core (bearerbox core)

It has more properties such as allowed IP list and other security related settings. When running for production care should be taken to set it up appropriately for your application

dlr-storage = mysql means to store the intermediate process results in a table and read it back when its needed. When Kannel submits the SMS to the SMSC, then SMSC will return the results whether the SMS has been delivered or lost, or any other information as a delivery report back to the Kannel. This information will be stored in a database (according to the configuration it will be in MySQL) for an intermediate use and will be processed again when the application requests for a delivery report. It’s more reliable to use a database in the production, but for testing it could be set to dlr-storage = internal. Then kannel will store the results in memory and return it to the application when it’s requested via callback URL.

When using MySQL the following properties should be added in the configuration file.

Table kannel_dlr will have field from SMSC to boxc_id. All these fields will have the datatype as varchar.

2. Connecting to the SMSC

Kannel bearerbox has to connect with the SMSC. Let’s look into setting up the SMSC. For testing we’ll be setting up with the SMSC simulator. When it ready for production, then we have to only change the IP address or port.

Username and password can be changed in the SMPP SMSC simulator. (It can be done inSMPPSim/conf/smppsim.props).

Now we have set up Kannel to use the SMSC simulator.

3. Configuring the smsBox

In the same configuration file, we’ll be adding another section. This section will contain all the necessary details for the smsBox to run.

We have to setup a user/password, which will be used to access the http service to submit the SMS. More details from the Kannel user guide.

Starting the server

Now the entire configuration is done. Let’s fire up the engines. First start the SMPP SMSC simulator.

Make sure Java path is setup. Ok. Simulator has started.

Next start the Kannel components in following order.


Ok. Kannel components have been started. Log files and console will display errors when they occur. Make sure to set the log level to “debug” when developing.

According to the SMPP protocol, client and the SMSC will be sending enquire_linkmessages to check whether either end are active. By default, Kannel will send this message every 30 second. Depending on the SMSC, it should be changed.

Now we write some simple Java code which is going to send the SMS. It will be using the HTTP GET method to submit the request.

Note that we can send normal text messages as well as binary messages. Binary message could be OTA configurations, WAP push, ringtones … etc. (See this article for more details on sending binary messages).

Let’s look at sending a normal text message message.

When sending the binary message, remember to encode the message.

param.append(‘&text=’).append(‘%01%06%2F%1F%’); //it could contain 256 chars
param.append(‘&coding=’).append(‘1’); //Its the DCS field and setting it to be 8bit binary message

Now setting the delivery report callback URL:

Now we have submitted the SMS request and the delivery receipt will be delivered by replacing the values in the callback URL. This callback URL is a Servlet which will simply get the parameter and value from the URL and logged it to a file or database for tracing purpose.

This is a just a scratch on the surface of Kannel, SMPP and SMSC. Hope it helps to start using these technologies.

Source :

Show Buttons
Hide Buttons