Home > Linux > Smart and Simple Mail to SMS Gateway

Smart and Simple Mail to SMS Gateway

This is a simple guide for configuring a simple (but smart :-)) Mail to SMS gateway. It is based on the FOX BOX platform for sending out SMS. You will need a Linux server with the Postfix MTA configured. Besides, you will need at least the following additional packages:

  1. mimedecode
  2. lynx
  3. URLENCODE.sh shell script by Heiner Steven ( heiner.steven@odn.de) to perform TEXT to URL encoding transforms
  4. formail which is part of the procmail package

This e-mail address is being protected from spam bots, you need JavaScript enabled to view it You will be able to send an email to an address like smsto+YOURNUMBER@smsgw.yourdomain.com and it will be automagically converted as an SMS containing the sender e-mail and the subject. This implementation is partially derived from this article.

The destination number must be in the form CCNNNMMMMMMM, with the country code (CC) explicit.

Configure your mail system in order to deliver mail for the smsgw.yourdomain.com through the Postfix box (dedicated server, virtual domain, what ever you prefer).

On the Postfix server make sure that it is configured to use procmail as MDA and that you have the recipient_delimiter defined like this (in /etc/postfix/main.cf):

mailbox_command = procmail -a "$EXTENSION"
recipient_delimiter = +

Next create a normal Unix account named “smsto”. Next configure procmail for this account with the following recipe:

MAILDIR=$HOME/Mail      # You'd better make sure it exists
LOGFILE=$MAILDIR/log.`date +%y-%m-%d`


        :0 c
        | formail -c -X From: -X Subject: | \
             mimedecode | $HOME/bin/convert2sms.sh $SMSDEST


Next prepare the following Bash script in $HOME/bin of the smsto user:


# for debugging
# set -x

if [ $# -ne 1 ]; then
        echo "$0: Please specify the destination phone number (39XXXYYYYYYY)"
        exit 1

# Path to urlencode.sh script
# Path to Lynx
# Where we save the output read from Formail
# Clean up when done
trap "/bin/rm -f $TEMPFILE" 0 1 2 3 15

# TODO: check the right pattern of the number

while read line; do
        echo "${line}" >> $TEMPFILE

# In $TEMPFILE we expect something like this:
# From: some1@somewhere.org
# Subject: the mail subject

# With tr we strip the " char (bug in FOX BOX UI)
# With cut we trim down the size of the field
# We want to stay in the 160 char limit of SMS messages
FROMLINE=`grep -i ^From: $TEMPFILE | tr -d '42' | cut -b -40`
SUBJLINE=`grep -i ^Subject: $TEMPFILE | tr -d '42' | cut -b -117`

logger -i -t SMSTO "$FROMLINE"
logger -i -t SMSTO "$SUBJLINE"


logger -i -t SMSTO "$MESSAGE"

# Prepare the URL

CMDS=`$LYNX -dump $SENDURL >/dev/null`

exit 0

Substitute your SMS BOX Admin password in the SENDURL variable. It is still rudimentary since some sanity checks are missing, but it works for me. YMMV.

  1. Non c'è ancora nessun commento.
  1. No trackbacks yet.


Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione / Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione / Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione / Modifica )

Google+ photo

Stai commentando usando il tuo account Google+. Chiudi sessione / Modifica )

Connessione a %s...

%d blogger hanno fatto clic su Mi Piace per questo: