How to create an Email to SMS Gateway

How to create an Email to SMS Gateway

This document explains how you can use postfix to call a script, with the result that you can then interface email to our RestFul SMS gateway API or our Simple SMS Gateway API.
We also have a EMAIL to SMS GATEWAY product, the link provides full details.
Integrating Email to our SMS Gateway
You will require some programing knowlege to configure your systems to send email to the SMS API. We will be using email piping to achieve this goal.
Step 1. Configure email piping.
In this example we will be using Postfix (the common open source SMTP server).
First configure an email account (from the sms user account) you wish to send the SMS mail to, for example sms@mydomain.com. This email address will receive all the emails that will get converted into SMS. Then:
– Edit alises
– # nano /etc/aliases
– Add the alias with piping to the file:
– sms: “|/var/www/scripts/emailGateway/processEmail.sh”
– Save and exit and update aliases database:
– # newaliases
Next is to set up the routing in postfix to point to the “sms” alias.
– Edit the virtual file of postfix:
– # nano /etc/postfix/virtual
– Add the routing info:
– sms@mydomain.com sms
– Save and exit.
– Now edit the postfix config file to use the virtual database:
– # nano /etc/postfix/main.cf
– Add the following line:
– virtual_maps = hash:/etc/postfix/virtual
– Save and exit.
– Note: This is only needed if postfix hasn’t been configure to work with the virtual database yet, if you find the above line already in the config file just ignore this step.
Reload Postfix:
– # postfix reload
Step 2. Read and process the email data
Next up is to create the file processEmail.sh this is the shell script that will get called when email arrives at the SMS account. In our example we are going to get it to call a php script like this:
php /var/www/scripts/emailGateway/send.php
Close and save the file.
Finally we want to use the data, to do this start your php script with the following code:
$FileHandler = fopen(“php://stdin”, “r”); if ($FileHandler > 0) { while(!feof($FileHandler)) { $RawEmailContent .= fgets($FileHandler, 120); } }


This will read the email data into a string which you can then parse and send to our API, see our API documentation



More articles about...

Popular posts

View our infographics View our helpful guides SMS Web Pages