E-mail to SMS

If you are dealing with network monitoring, you might consider using SMSes because they are completely independent. On the other hand, many monitoring systems don’t support  HTTP calls (which is the usual way for sending them) but most of them support sending e-mails. Here I want to describe how to configure your server to receive e-mails and transform them to SMSes.

You will need:

  • Linux server (in my case Debian based)
  • 4G/3G/2G USB modem plugged in with SIM with PIN disabled


  1. Install packages
    $ apt install postfix smstools usb-modeswitch procmail
  2. disable PIN on your SIM card
  3. reinsert USB modem after installing usb_modeswitch
  4. create user sms
    $ adduser sms
  5. configure postfix
    1. setup local mail delivery the usual way
    2. add procmail processing:
      mailbox_command = procmail -a "$EXTENSION"
    3. $ systemctl enable postfix
    4. send a test e-mail to address sms+12345@<yourserver>
    5. check if it is received in $HOME/Mailbox or /var/spool/mail/sms
  6. configure smstools
    1. edit /etc/smsd.conf, in my case the following section was enough:
      device = /dev/ttyUSB0
      init = AT^CURC=0
      incoming = yes
      baudrate = 19200
    2. $ service smstools restart
    3. test if SMS sending works by creating SMS:
      $ cat << EOF > /var/spool/sms/outgoing/test
      To: +421903123456
      test sms
    4. $ systemctl enable smstools
  7. login as sms user
    $ su sms
  8. create $HOME/.procmailrc file with the following contents:
    # store mail in default folder and continue after that
    | umask 000 ; $HOME/email-to-sms.py
  9. create $HOME/email-to-sms.py file with the following contents:
  10. chmod +x email-to-sms.py
    usermod -a -G smsd sms
  11. edit email-to-sms.py to allow permitted senders
  12. send email to sms+destinationnumber@<yourserver> and watch the magic

How does it work?

In email systems, it’s common that you can use plus sign to deliver to same mailbox (the portion before +)  and to “tag” your e-mails (the portion after +) (Subaddressing). So all emails are delivered to user “sms”.

The next component we use is procmail which can do many sorts of useful filtering, in our case we let all e-mails to be delivered to the mailbox but then we also pipe them to a special script named email-to-sms.py

email-to-sms.py then parses the incoming e-mail, extracts sender and destination number, checks sender whitelist, extracts plain-text message content and creates SMS in outbound queue of smsd.

smsd then only simply sends the message via attached modem.

Easy, isn’t it? 🙂

5 thoughts on “E-mail to SMS”

  1. I have the same problem.
    E-mail is generated och I can send SMS manually, but can’t get procmail and email-to-sms.py running, Probably permissions issues.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.