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:
- A regular PC
- Nokia phone running Symbian OS, connected to the USB port in “PC Suite” mode
- Fedora 12, with Postfix (personally, I don’t like Sendmail)
- 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
Now, just for the sake of better organization, I have created a user under which we will run the SMS system, and fixed the file permissions to match that user.
# useradd -r sms # mkdir /var/run/smsd # chown -R sms.sms /var/log/smsd.log /var/spool/sms /var/run/smsd
Then we need to configure smstools with the minimum parameters necessary for it to run.
# vi /etc/smsd.conf + loglevel = 5 + user = sms + group = dialout + infofile = /var/run/smsd/smsd.pid + pidfile = /var/run/smsd/smsd.working + device = /dev/ttyACM0
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 # smssend 551199999999 "This is a short test." # 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 # vi /etc/postfix/master.cf + smstools unix - n n - - pipe + flags=DORhu user=sms 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 Trying 10.1.1.100... Connected to smsgateway.example.com (10.1.1.100). 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: 551193278997@smsgateway.example.com 250 2.1.5 Ok data 354 End data with . To: 551193278997@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!
Escrito por netmask 