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:

PATH=$HOME/bin:/usr/bin:/bin:/usr/local/bin:.
MAILDIR=$HOME/Mail      # You'd better make sure it exists
DEFAULT=$MAILDIR/mbox
LOGFILE=$MAILDIR/log.`date +%y-%m-%d`
LOCKFILE=$HOME/.lockmail
VERBOSE=yes

SMSDEST=$1

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

        :0
        received
}

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

#!/bin/bash

# for debugging
# set -x

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

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

# TODO: check the right pattern of the number
PHONE=$1

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

# 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"

MESSAGE=`echo $FROMLINE \| $SUBJLINE | $URLENCODE`

logger -i -t SMSTO "$MESSAGE"

# Prepare the URL
SENDURL='http://srv-sms/source/send_sms.php?username=Admin&pwd=PASSWORD\
&from=smsgw@yourdomain.com&nphone='$PHONE'&testo='$MESSAGE

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.

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

Lascia un commento

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 cliccano Mi Piace per questo: