Open the Mobile Gateway with SMS and MMS Messaging

Open the Mobile Gateway with SMS and MMS Messaging

Short Messaging Service (SMS) services are becoming near-ubiquitous. Who among us has not used their cellphone to check the latest cricket score or to get the latest news? One very popular service, available through most carriers, is Yahoo’s 8242 service. This service allows you to check your Yahoo Mail, use Yahoo Instant Messenger, or check scores, news, etc. When you access this type of service, you’re using both the carrier’s network and the service provider’s network (in this case Yahoo). There are also many carrier-dependent services, in which case you make use of the carriers’ network alone.

To provide you with these services, these networks (Yahoo, or any of the carriers like Hutch, AirTel, etc.) implement something known as a gateway. A gateway is nothing but?as the word suggests?an entrance to the network. In the case of mobile-based services, these gateways are called mobile-to-network gateways,or simply mobile gateways.

This article uses a low-level implementation to demonstrate how a mobile-to-Web gateway works. The example network uses the Web, but carriers and service providers may use their own networks.

What Is a Gateway?

Figure 1. A Typical Gateway: The image shows a typical gateway.

Typically, a service has many users. The gateway (depicted as a thick line in the service network in Figure 1) performs the following tasks:

  • Implements a queuing mechanism to service each incoming request.
  • Determines whether the the service requested is acceptable.
  • Sends a response granting the service.

Thus, a gateway acts as a filter between the service network to the service requester (user’s) network.

The sections that follow provide an overview of an SMS-to-Web gateway, and an MMS-to-Web gateway. For simplicity’s sake, the examples assume only one user. This leaves the task of implementing mobile gateways that service incoming mobile requests (in the form of SMSes and MMSes) on a continuous basis.

The SMS-to-Web Gateway
Here are the three things a required to implement a gateway:

  1. An incoming service request from a mobile (in this case in the form of SMSes).
  2. A number to send the service request.
  3. A service network (typically).

To satisfy the first of the above requirements, you may use any cell-phone (note that the network type?whether GSM or CDMA?determines availability of service numbers).

The main task is to provide your own service, using your own gateway. Since you don’t have your own service number or your own network, you’ll need to use an intermediary service?like Yahoo Mail for SMS?as a way to send requests. For your network, you’ll simply use the Web.

Before you implement your gateway, you’ll need to decide what service you want to offer. This example uses a simple model: a user sends SMSes which are displayed as plain text on the sender’s home computer.

The user will send messages using a service like Yahoo Mail for SMS. This service is offered by Yahoo to select carriers (like Hutch, Orange, etc.). Users are able to send emails from their Yahoo mail account using SMS. Here’s how to send an email using Yahoo Mail:

Login to your account by SMSing the following to 8243 (this is Yahoo’s service number, more commonly called the Yahoo Gateway):

in username password

To send an email, SMS the following to 8243:

to [email protected] mail_body

In this case, you’re the only user, so the recipient email address will be one of the user’s email addresses.

Because the Web is your intermediate network, the user’s home machine should be connected to the internet at all times. Your gateway?which is software?will be implemented on this machine.

The gateway is like a daemon?whenever a new request comes in, the gateway services it. More specifically, the gateway is an endless (infinite) loop that sleeps in between events for a pre-defined time, meaning it’s not a tight infinite loop. In this case, the service is simply displaying the SMS.

Figure 2. The Scheme of Things: This shows how the gateway fits into the scheme of things.

Take a more detailed look at how the gateway grants service requests:

  • The user sends an SMS to one of his own email addresses. The email address could be a Web mail account or a POP3 account, which is even better.
  • The gateway is running in the background. It uses the Internet to access the user’s mail account to check for new emails. New emails are filtered to get only those emails that have been sent via SMS. The simplest way to do is to check for the subject, which is typically set to ‘[none]’ when using Yahoo Mail for SMS.
  • The gateway parses the raw email source, and extracts only the body of the email, simply displaying it in the console.
  • After one round of processing, the gateway “sleeps” for a while.
  • After the sleep period is over, it springs back into action.

Now, you have implemented an SMS gateway. The gateway fits into the scheme of things as shown in Figure 2. The pseudocode in Listing 1 shows the overall logic flow for building the gateway.The MMS-to-Web Gateway
Just as you implemented an SMS gateway, you can implement an MMS (Multimedia Messaging Service) gateway. What’s the difference between an SMS and an MMS?

SMS messages can only contain text/plain messages, while emails sent using MMSes have textual as well as multimedia data (typically images). Thus, MMS messages are “multipart” messages?the MIME type part of the email could be text/plain, and the other part could be an image/jpeg.

So the only difference between an SMS gateway and an MMS gateway is in how each handles the various MIME extensions of the email.

Note: In an SMS message, the MIME type can be text/plain only, so you don’t have to explicitly handle such email messages.

The MMS gateway is identical to the scheme shown above for the SMS gateway.

Listing 2 shows how to implement the MMS gateway as pseudocode.

SMS-to-LiveJournal: An SMS-to-Web Gateway
For those of you who have not heard of LiveJournal, it’s a very popular blogging Web site that runs on open-source software. I recently wrote an SMS-to-LiveJournal gateway (simply called SMS2LJ). The source?written in Python?is available under the terms of the GNU Public License (GPL) at

This tool is similar to the SMS-to-Web gateway that I discussed earlier. Where it differs is in the service provided?using this tool, a user can send an SMS, which then is processed by the gateway, but instead of simply displaying the message on the computer, the message is posted to your LiveJournal account. This allows you to post to your LiveJournal account whenever you are on the move.

Instead of using the display() function, you use the postToLiveJournal() function:

function postToLiveJournal(what) {server = "";data = {user: LJ_USER,password: LJ_PASSWORD,subject: "",message: what,year: time.getYear(),month: time.getMonth(),day: time.getDay(),time_hrs: time.getHours(),time_mins: time.getMinutes()}, server);}
Author’s Note: In the above pseudocode, the main functions run in an infinite while loop (with some “sleep” period). This was to demonstrate the idea behind how these gateways run continuously, polling whatever they are supposed to (POP3 mailboxes, etc.). However, using an infinite while loop is not a very good idea. Instead, when actually using the script, run the main function only once in the script, and schedule the script using a scheduler like cron.

Using a scheduler makes more sense. If you use a while loop instead, and if for some reason an error occurs, the script would halt. Thus, your gateway will no longer work until you re-run it. Errors in scripts are very common. To avoid such problems, use a scheduler. Even if an error occurs at a particular run, the script will be scheduled to run again.

Using Mobile-to-Web Gateways
The above example (SMS-to-LiveJournal Gateway), shows how to perform “moblogging,” or, blogging on the move. An even better way to achieve moblogging is to send multimedia messages using your mobile device?an MMS-to-LiveJournal Gateway. For those interested, I have written one (using Ruby). It’s available here.

There are plenty of ways you could use Mobile-to-Web Gateways:

  • Comment Alert: Most blogging tools allow readers to leave comments to your posts. You can easily create an application that would alert you (by way of SMS or MMS) when you receive a comment. This can be easily achieved by “parsing” your comments page, or even better using an API (if one is available) to keep track of comment counts.
  • Mail Alert: Another very interesting way to use Mobile Gateways is to create a mobile mail alert application. This application would in essence, poll your POP3 mailbox for incoming mails, and when one arrives, it would simply send an email to your gateway address (typically of the form [email protected]). This would make an interesting application for those on the move with handheld mobile devices. In fact, you could even message the entire text of the email, limited, of course, only by the SMS/MMS character limit imposed by your mobile phone operator.
  • Using such gateways, you could provide your own mobile service. For example, you could provide topical news. How? Well, you’d have a primary email address that acts as the target “address” to obtain a news service. People who want the service could simply send a message to that mail address, a typical message being of the form: news whetever-category. Your gateway simply polls your POP3 mailbox for such messages, parses them, and accordingly delivers the services!

There are many other useful ways to use gateways; if you think of one, drop me a line. I hope this article has helped you understand the idea behind gateways.


Share the Post:
XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes

ransomware cyber attack

Why Is Ransomware Such a Major Threat?

One of the most significant cyber threats faced by modern organizations is a ransomware attack. Ransomware attacks have grown in both sophistication and frequency over the past few years, forcing

data dictionary

Tools You Need to Make a Data Dictionary

Data dictionaries are crucial for organizations of all sizes that deal with large amounts of data. they are centralized repositories of all the data in organizations, including metadata such as