Posts Tagged ‘mail2sms sms mail gateway postfix procmail foxbox’

Smart and Simple Mail to SMS Gateway

agosto 4, 2008 Lascia un commento

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. shell script by Heiner Steven ( 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 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 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/

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/ $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 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:
# 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.