I do what I can

Random thoughts from Mauricio Teixeira…

Email to SMS gateway in Linux

with 17 comments

Updated on Jul/03 — Works on Fedora 13, a fix minor inconsistencies.

This is another one of my “quick and dirty” tutorials. This time I will show you how to build an email to SMS gateway.

Before we continue, bare in mind that I didn’t care to document details on system security (specially in what regards to spam filtering or SELinux configuration). The idea here is to show an overview on what needs to be done to have it working. I also won’t explain how to configure an MX entry in DNS, or how to make this integrate to your current email system. The details should be polished by whoever is going to implement, depending on their environment.

Tools I have used here:

  1. A regular PC
  2. Nokia phone running Symbian OS, connected to the USB port in “PC Suite” mode
  3. Fedora 13, with Postfix (personally, I don’t like Sendmail)
  4. SMS Server Tools 3 (installed from Fedora repository, using yum)

First thing I did was installing the SMS Server Tools application, Postfix and disabling Sendmail. I did that because I think Postfix is easier to configure and maintain. If you want to do this using Sendmail, and you find your way into it, please paste the necessary configuration lines on the comments below.

# service sendmail stop
# chkconfig sendmail off
# yum install smstools postfix

The package in Fedora 13 already adds a private user for the sms system, creates the necessary directories and sets the permissions. So we just go with what we get.

Now we need to configure smstools with the minimum parameters necessary for it to run.

# vi /etc/smsd.conf
+ devices = ACM0
+ loglevel = 5
+ group = dialout
+ infofile = /var/spool/sms/smsd.running
+ [ACM0]
+ device = /dev/ttyACM0
+ incoming = no

Important notes here. The device ttyACM0 exists because when I connected the Nokia I selected the “PC Suite” mode. If you select anything different, it will create a different device, but none of them work for sending messages. If you are doing this on a different distribution other than Fedora, check which group is the owner of this device, and set it on the smstools config file, otherwise the application won’t be able to write to the device.

Great. Now we can start the application, and run a basic test. Remember the accepted phone number format: XXYY99999999, where XX is the country code, YY is the region code, and the rest is the real phone number.

# chkconfig smsd on
# service smsd start
# su smstools -c "smssend 551199999999 'This is a short test.'"
# su smstools -c "echo -e 'To: 551199999999\n\nThis is a long test.\nWith multiple lines.\n' > /var/spool/sms/outgoing/test"

At this point, you should have received two messages. If you don’t, read back and double check your settings (or look at the logs). If all works, keep reading.

The final part is to make Postfix receive the messages, and route via smstools. The script that converts from email to SMS is this:

# cp /usr/share/doc/smstools-*/email2sms /usr/local/bin/
# chmod +x /usr/local/bin/email2sms

And here is how we make Postfix deliver to the script:

# vi /etc/postfix/main.cf
+ inet_interfaces = all
+ mailbox_transport = smstools
# vi /etc/postfix/master.cf
+ smstools  unix  -       n       n       -       -       pipe
+  flags=DORhu user=smstools argv=/usr/local/bin/email2sms
# chkconfig postfix on
# service postfix start

If you don’t set the inet_interfaces option, Postfix will only accept connections from localhost. If you need it to receive messages from anywhere in your network, better put something meaningful there.

Now we need to make Postfix understand what is considered to be a valid user on the server. For that, we keep the old /etc/aliases, and add our users:

# vi /etc/aliases
+ 551199999999: netmask
+ 551188888888: badnetmask
# newlaliases

Remember: for every SMS recipient there must be an entry in /etc/aliases. The name after the colon is mandatory because of the file format, but will make no difference to the delivery system, so just use something that will identify the user of that address.

At last, test it:

$ telnet smsgateway.example.com 25
Connected to smsgateway.example.com (
Escape character is '^]'.
220 smsgateway.example.com ESMTP Postfix
helo netmask.example.com
250 smsgateway.example.com
mail from: netmask@example.com
250 2.1.0 Ok
rcpt to: 551199999999@smsgateway.example.com
250 2.1.5 Ok
354 End data with .
To: 551199999999@smsgateway.example.com
Subject: Test subject
Hello world!
250 2.0.0 Ok: queued as C52E620236

That’s it!

I hope this is useful for you. If you find any mistakes or you wish to suggest any different setup to our next readers, please feel free to comment below.

Have fun! 🙂


Written by netmask

março 11, 2010 às 11:48

Publicado em Uncategorized

Tagged with , , , ,

17 Respostas

Subscribe to comments with RSS.

  1. […] Enviado por Mauricio Teixeira (mauricio·teixeiraΘgmail·com): “Escrevi um rápido tutorial sobre como criar um gateway de email para SMS usando Linux. Fiz isso em laboratório, apenas como prova de conceito, portanto o documento é apenas um guia para auxiliar quem deseja criar um sistema real.” [referência: mteixeira.wordpress.com] […]

  2. […] post: Email to SMS gateway in Linux « I do what I can Posted in Postfix | Tags: connection, courier, domains, from-http, installing-the-sms, […]

  3. […] Email to SMS gateway in Linux From I do what I can […]

  4. Hi,
    Thank you for the article.
    I am trying this with smstools3 on Fedora 7.
    I have couple of questions:
    1. Do I have to add a line in /etc/aliases as
    nnnnnnnn: username
    where nnnnnnnn is the user’s phone number with country code?
    2. To use this, do I send a mail to username@hostname.domainname
    or do I send email to username nnnnnnnn
    as shown in email2sms script?
    Please reply.
    Thanks in advance.

    J Dubal

    julho 1, 2010 at 07:28

    • Correct, the alias entry is always country code + area code + number, followed by a colon and the name of the user of the phone.

      The message should be sent to the phone number, not to the user name.

      Of course you can create a reverse alias, that will map a user to a phone. 🙂


      julho 1, 2010 at 09:27

      • Thanks for the reply.
        I sent mail to number@mailserver.com.
        It gets promptly translated by /etc/aliases to name@mailserver.com and postfix delivers it to the user’s mailbox.
        How will that call emal2sms script and send sms?
        I have added the 2 lines to /etc/postfix/master.cf.
        It is not sending sms. Please help.

        J Dubal

        julho 1, 2010 at 11:06

        • I did a little review, and fixed minor issues. Re-check the instructions and see if that would work for you.

          Also, I tried the alias from name to phone, and it does not work. The problem is in the email2smstools script, it needs to be rewritten. I’ll try to add some more features when I find some tome to work on it.

          Well, as I said in the beginning, it’s a dirty method, and not perfect. Sorry.


          julho 3, 2010 at 21:49

  5. I am looking for a simple way to configure a local sms gateway for j2ee and php apps

    Its a good tip and so simple than I need.

    Before I test, can you tell if smstools work with other mobiles or it needs a Symbian OS phone ?


    Alexandre Rocha

    julho 21, 2010 at 21:37

    • It might work. The difference would be which option you should set on your device when it connects via USB, and which would be the name of the device in Linux. smstools use plain AT commands, and is very configurable. Just read the config file and it will give you the needed directions for your phone.


      julho 21, 2010 at 23:44

  6. […] The busiest day of the year was 12 de março with 692 views. The most popular post that day was Email to SMS gateway in Linux. […]

  7. […] The busiest day of the year was 12 de março with 692 views. The most popular post that day was Email to SMS gateway in Linux. […]

    • Does not work the connection between postfix and smstools, my logs:
      Apr 22 13:51:19 swa125 postfix/smtpd[2520]: connect from unknown[]
      Apr 22 13:51:19 swa125 postfix/smtpd[2520]: 6F0D5C0747: client=unknown[]
      Apr 22 13:51:19 swa125 postfix/cleanup[2523]: 6F0D5C0747: message-id=
      Apr 22 13:51:19 swa125 postfix/qmgr[2487]: 6F0D5C0747: from=, size=1356, nrcpt=1 (queue active)
      Apr 22 13:51:19 swa125 postfix/smtpd[2520]: disconnect from unknown[]
      Apr 22 13:51:19 swa125 postfix/pipe[2525]: 6F0D5C0747: to=, orig_to=, relay=smstools, delay=0.24, delays=0.13/0.04/0/0.08, dsn=2.0.0, status=sent (delivered via smstools service)
      Apr 22 13:51:19 swa125 postfix/qmgr[2487]: 6F0D5C0747: removed

      /var/smsd/smsd.log (switch on logging in /etc/smsd.conf)
      2012-04-22 13:11:52,7, ACM0: AT+CIMI
      2012-04-22 13:11:53,7, ACM0: Command is sent, waiting for the answer
      2012-04-22 13:11:53,7, ACM0: AT+CGSN
      2012-04-22 13:11:53,7, ACM0: Command is sent, waiting for the answer
      2012-04-22 13:11:53,7, ACM0: <- 358672012720334 OK
      2012-04-22 13:11:53,5, ACM0: CGSN: 358672012720334
      2012-04-22 13:11:53,5, ACM0: IMSI: 260021062720024
      2012-04-22 13:11:53,5, ACM0: Waiting for messages to send…

      Please help me 😉
      Best Regards


      abril 22, 2012 at 08:57

      • Robert,

        My tests were a long time ago. I imagine both smstools and postfix evolved and changed. Maybe would I need to try again and review my notes, however timing is not optimal for that.

        If you figure anything out, we appreciate your collaboration.


        abril 22, 2012 at 11:39

  8. Hy it’s a nice post but i wish you can have more post on SELinux 🙂


    agosto 2, 2012 at 04:23

    • Sorry, it’s going to be hard to do that since I have abandoned the project in favor of others. Maybe I can try it again some day and see what I can figure out. 🙂


      agosto 2, 2012 at 07:27

  9. […] Email to SMS gateway in Linux | I do what I can – July 19th ( tags: sms gateway linux tutorial guide setup ) […]

Deixe um comentário

Preencha os seus dados abaixo ou clique em um ícone para log in:

Logotipo do WordPress.com

Você está comentando utilizando sua conta WordPress.com. Sair /  Alterar )

Foto do Google+

Você está comentando utilizando sua conta Google+. Sair /  Alterar )

Imagem do Twitter

Você está comentando utilizando sua conta Twitter. Sair /  Alterar )

Foto do Facebook

Você está comentando utilizando sua conta Facebook. Sair /  Alterar )


Conectando a %s

%d blogueiros gostam disto: