Sending SMS from Apps and Webapps

It’s easy to send SMS messages from any Web site or application, but it’s surprising how few sites/applications actually do this. Integrating SMS into your system gives it something extra, and allows your system to enhance the mobile experience for the user. In this article, we’ll look at how an SMS message can be sent from any system, and at a few providers who offer this functionality.

Choosing an SMS Provider

There are essentially three types of SMS provider:

  • Mobile Network (e.g. Vodafone, Three)
  • Aggregator
  • SMS Messaging Company

Mobile Network

To send messages through a mobile network, you need to set up a Short Message Service Centre (SMSC). These are being replaced with SMS routers, which are more efficient. It’s very unlikely you’ll set up an account directly with a network, as the costs are prohibitive. You need to be sending a few million messages per day before a network will even consider talking to you.

Aggregator

Think of an aggregator as a go-between, sitting between you and the network. Aggregators set up an SMSC with one or more networks and allow users that want to send SMS messages to send those messages through their connection. By gathering up a large number of small users, the message numbers are aggregated (you can see where the name comes from), giving the aggregator enough messages per day to maintain their SMSC connection with the network.
Depending upon the aggregator you pick, costs will vary. Generally you’ll pay anywhere between 2p – 7p per message, and maybe a monthly fee. The API you’ll use will involve either a SOAP Web service, an XML-RPC Web service, or HTTP POST/GET calls.
There are lots of aggregators, here’s a sample:

  • Esendex
  • 2ergo
  • iTagg (supports MMS)
  • Tanla
  • Reach Data

SMS Messaging Company

SMS messaging companies are third party companies who publish an API that allows you to send SMS messages. To all intents and purposes these companies are much the same as an aggregator. Examples of such companies are txtlocal and txtnation. These companies often offer installable software which allows you to upload lists of mobile numbers to which SMS messages can be sent.
When it comes to choosing a provider, you need to think about what you are trying to do. Some common requirements to consider are:

  • Do I need to send SMS messages?
  • Do I need to send bulk SMS messages?
  • Do I need to send MMS messages?
  • Do I need to receive messages?
  • Do I need to send long messages (messages greater than 160 characters in length)
  • How much will each message cost me?

If you only aim to send SMS messages, you can choose pretty much any provider you want. If you want to send SMS messages via your site or application, you’ll need to choose a provider with an API.
Remember that you’ll be charged for each message sent (2p to 7p). You can either pre-pay or arrange a monthly direct debit with most providers; it depends on how many messages you think you’re likely to send.

Adding SMS Functionality to Your System.

As you have a mobile system, it’s a natural progression to add mobile-related technologies to it. It enhances the mobile experience and allows the user to better interact with the system. The BBC Mobile site, for example, displays a small blue SMS icon at the bottom of each article. Clicking on this displays a screen that allows you to send an SMS to a friend:


Figure 1: BBC mobile site SMS interface

It’s this kind of use that can really take your mobile system to another level.
To show you how to send an SMS message, I’m going to use the iTagg API. The first thing to do once you’ve selected an SMS provider is to download or request their API documentation (you can download the iTagg API documentation from here). The level of implementation difficulty changes from API to API, but none of them are particularly challenging for a competent developer. Most APIs also offer error codes, so you’re informed if something goes wrong when sending a message.

Once you have the API document, request a trial. This will allow you to send some SMS messages. You’ll be given a user name and password, which you’ll need to follow the example below.
The iTagg API supports a HTTP POST-based mechanism. Here are the parameters we need to specify:

  • Usr – The user name for your iTagg account.
  • password – The password for your iTagg account.
  • from – The number or alias you want the message to appear to have been sent from. If you specify a text-based alias, you can specify up to 11 characters. If you specify a valid UK mobile number you can specify up to 12 characters, as a mobile number with a country code is 12 characters long. Note: if you intend to allow users to reply to SMS messages, you must specify a mobile number.
  • to – The mobile number you want to send the message to.
  • Txt – The message body you want to send. Remember this can only be up to 160 characters in length. You can send longer messages using contatenation if you require – but not all the provider APIs support this.
  • type – Although I’ve only discussed SMS messages so far, it’s usually also possible to send binary or WAP Push messages. The iTagg API allows you to specify the message type to send using this parameter.
  • send – This optional parameter allows you to specify a date and time to send the message, so you can schedule it. If no scheduled date/time is specified, the message is sent immediately.
  • route – Some providers ask you to specify a route – iTagg is one such provider. This often determines how fast the message will arrive once you’ve sent it, and how much you will be charged for sending the message.

We’ll create a simple Web site using Visual Studio 2008 to show how to send a message.
1. Open Visual Studio and create a new ASP.NET Web site.
2. Open the Default.aspx page in design view and add the following controls:

  • A label called lblTo, with the text value set to To:
  • A text box called txtTo
  • A label called lblFrom, with the text value set to From:
  • A text box called txtFrom
  • A label called lblBody, with the text value set to SMS Message:
  • A text box called txtBody, with the TextMode set to MultiLine
  • A button called btnSend, with the text value set to Send
  • A label called lblResult, with the text value set to nothing (i.e. an empty string)

Once you’ve done this, rearrange the controls so they are displayed on individual lines, as in the image below.


Figure 2: Visual Studio – form controls layout

3. Now we can add some code to actually send an SMS message. Bear in mind that, for easier demonstration, I’m going to hard-code everything into the btnSend_Click event. In reality, things like the user name and password would be stored in the web.config file.

Double-click the Send button to create the button’s click event handler:


Figure 3: Visual Studio – send button event handler code

4. Enter the following code (make sure you replace username and password with the appropriate values):


Figure 4: Visual Studio – send button event handler code

5. Now press F5 to run the Web site. Type in some details, ensuring you specify a valid mobile number. Then click Send. You should see a response appear below the Send button, and the message should be delivered to your phone.


Figure 5: iTagg SMS API Message Demo – browser output


Figure 6: Receiving SMS – phone display

6. It really is that easy to send an SMS message – four lines of code! But what’s the response string that was displayed after we clicked the Send button? Let’s take a closer look.

error code|error text|submission reference 0|sms submitted|2891717007c4bf0ebf2c81cb4995cd2d-3

iTagg returns a pipe-separated list of return values. The first two are self-explanatory – if an error occurs, an error code and error text are displayed. In a fully implemented solution, your program would handle the various error codes returned by iTagg and could respond appropriately. No error has occurred here, so the error code is set to 0 (denoting success), and the error text is set to sms submitted.
The final value is the submission reference. This is an identifier for the message, which can be stored in your system to identify the message. This is useful because it allows us to process delivery receipts for this message – which we’ll discuss in a follow-up article.

Summary

We’ve just shown that SMS sending capabilities can, with relatively little effort, be added to any system. There are a large number of SMS providers out there so it’s important to think about what you need before choosing one. Most of the providers offer some type of HTTP-based API, which can be quickly integrated into your chosen system.
SMS providers can do more than just send SMS messages; they can also help you receive them and can also process delivery receipts too, so you can demonstrate that an SMS message arrived at its intended target. We’ll discuss these features in a separate article – happy sending!

Exclusive tips, how-tos, news and comment

Receive monthly updates on the world of mobile dev.

Other Products

Market leading device intelligence for the web, app and MNO ecosystems
DeviceAtlas - Device Intelligence

Real-time identification of fraudulent and misrepresented traffic
DeviceAssure - Device Verification

A free tool for developers, designers and marketers to test website performance
mobiReady - Evaluate your websites’ mobile readiness

© 2024 DeviceAtlas Limited. All rights reserved.

This is a website of DeviceAtlas Limited, a private company limited by shares, incorporated and registered in the Republic of Ireland with registered number 398040 and registered office at 6th Floor, 2 Grand Canal Square, Dublin 2, Ireland