Easy Guardian provides alarms by texting system administrators
If you would like to monitor you server 24h/24h this is the right tool for you! It brings together NMAP and Net-SNMP in a small silent Linux embedded box.  Visit: http://www.easyguardian.com
FoxBox arrow How-to arrow Email to SMS custom scripts
English
Email to SMS custom scripts PDF Print E-mail

In this tutorial we are going to explain how EMAIL to SMS function works and how to build a custom gateway.
The gateway downloads every 30 seconds the email messages from the mailbox specified in the configuration.

Warning: In the latest software versions we inserted the parameter "trust_outgoing = yes" to speed up communications.
We discovered that this gives problems to "email to SMS" feature, so please check the file smsd.conf and eventually delete this row if you need it. 

Use Email to SMS gateway function

The Email to SMS gateway feature require only four configuration parameters. You reach them from the web browser interface of the FoxBox, clicking on the left menu the "System profile" entry. Here there are three sections, and we are interested in the last one, titled "Incoming mails configuration for message forward MAIL to SMS".

As an example, we will configure the email retrieval of  This e-mail address is being protected from spam bots, you need JavaScript enabled to view it This e-mail address is being protected from spam bots, you need JavaScript enabled to view it In the first field you have to put the server that hosts the email account designed for SMS operations (ex. mail.kdev.it). In the second field you can specify which protocol to use for mail retrieval between POP3 and IMAP (default is POP3). In the third field you have to type the login name for access the email account (ex. gsm). In the fourth field you have to put the password for access the mailbox.

After these assignments, click on "Save configuration" to apply changes and proceed enabling the Gateway Engine on the "Control Panel" entry of the menu.

Now that the gateway engine is started, if you send a message to This e-mail address is being protected from spam bots, you need JavaScript enabled to view it This e-mail address is being protected from spam bots, you need JavaScript enabled to view it   using the following syntax: "Subject: TOsms From: To: 39349000111222 Text of your message" the email messages will be automatically diverted to the phone number 39349000111222. A screencast that demostrate this functionality is available here.

The architecture is based on FETCHMAIL + PROCMAIL.

Fetchmail is the program that downloads the emails, procmail is the program used to filter it. A predefined set of procmail rules is saved into your SMS FoxBox /etc/ folder in the file procmailrc.
The default rule is  explainded below:

SHELL=/bin/sh
VERBOSE=OFF
MAILDIR=/mnt/flash/root/procmail
DEFAULT=/mnt/flash/spool/mail/mails
LOGFILE=/mnt/flash/spool/mail/procmail.log

:0
*  ^Subject:.*TOsms
{
:0 b:  mail.body.lock
| /etc/sms/scripts/email2sms
}

 

In the first part, some environment variables are declared, the "TRUE" rule starts with :0 and we define the subject that the email message should have to be diverted to the SMS engine. Feel free to change the ^Subject:.*WHATYOUWANT, if you leave the ^Subject:.* all mails will be forwarded as SMS.
In the second part :0 b: we ask procmail to extract the WHOLE body of the email and forward it as SMS. Thanks to some user experience we noticed that with Lotus Notes the body of the email is altered with some extra carriage return so please if YOU ARE A LOTUS NOTES USER, update the line:
| /etc/sms/scripts/email2sms
with
| grep -v ^$ | sed '/To:/G'  | /etc/sms/scripts/email2sms

If you want to modify how the email message is processed, you have to learn some BASIC RULES of procmail that are well described on this UNOFFICIAL WEBSITE.

Here I will show you a rule to divert an email message "catching" the number from the email sender and the message from the body of the email.  So if you send an email FROM: This e-mail address is being protected from spam bots, you need JavaScript enabled to view it This e-mail address is being protected from spam bots, you need JavaScript enabled to view it to the defined mailbox (used by fetctmail and setted up on the profile of your box) the message will be sent to 393494603237.

SHELL=/bin/sh
VERBOSE=OFF
MAILDIR=/mnt/flash/root/procmail
DEFAULT=/mnt/flash/spool/mail/mails
LOGFILE=/mnt/flash/spool/mail/procmail.log
#OUTFILE="/mnt/flash/spool/smsgw.out.XXXXXX"
OUTFILE=$(/bin/mktemp /mnt/flash/spool/outgoing/smsgw.out.XXXXXX)

:0
*  ^Subject:.*TOsms
{
:0
* ? OUTFILE=$(/bin/mktemp /mnt/flash/spool/outgoing/smsgw.out.XXXXXX); echo $OUTFILE > /var/temp.txt; echo "From: MYNAME" >$OUTFILE; /etc/procmail/formail -t -x"From:" | awk 'BEGIN { FS = "<" } ; {print $2}' | awk 'BEGIN { FS = "@" } ; {print "To: "$1}' >> $OUTFILE

:0 b:  mail.body.lock
| OUTFILE=`/bin/cat /var/temp.txt`; echo "" >> $OUTFILE; /bin/cat  |grep -v ^$ | sed '/To:/G' >> $OUTFILE
}


Put this script in /etc/procmailrc and restart the EMAIL TO SMS Gateway to check it.

Another interesting  feature should be to send the SUBJECT of the email instead of the body as text message. To perform this simply edit the script as follows:

SHELL=/bin/sh
VERBOSE=OFF
MAILDIR=/mnt/flash/root/procmail
DEFAULT=/mnt/flash/spool/mail/mails
LOGFILE=/mnt/flash/spool/mail/procmail.log
#OUTFILE="/mnt/flash/spool/smsgw.out.XXXXXX"
OUTFILE=$(/bin/mktemp /mnt/flash/spool/outgoing/smsgw.out.XXXXXX)

:0
*  ^Subject:.*TOsms
{
:0
* ? OUTFILE=$(/bin/mktemp /mnt/flash/spool/outgoing/smsgw.out.XXXXXX); echo $OUTFILE > /var/temp.txt; echo "From: MYNAME" >$OUTFILE; /etc/procmail/formail -t -x"To:" | awk 'BEGIN { FS = "<" } ; {print $2}' | a
* ? OUTFILE=`/bin/cat /var/temp.txt`; echo "" >> $OUTFILE; /etc/procmail/formail -t -x"Subject:" |grep -v ^$ | sed '/To:/G' >> $OUTFILE
   # | egrep -i "@kdev\.it" >> /mnt/flash/test.txt
}

Obviously, with procmail you can process each header of the email and build the rules for your purposes. For example extract the "To" header instead of the "From" header or check that the body does not contain some words (moderation), this is the power of Open Source, the power of SMS FoxBox!

 

 
< Prev   Next >

buy foxbox
buy on FoxBox eShop



For further info contact us by mail This e-mail address is being protected from spam bots, you need JavaScript enabled to view it providing us the FoxBox model you need and your company details.

KDEV di Davide Cantaluppi, P.IVA 02984320131

http://www.kdev.it