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
Installation
- Install packages
$ apt install postfix smstools usb-modeswitch procmail
- disable PIN on your SIM card
- reinsert USB modem after installing usb_modeswitch
- create user sms
$ adduser sms
- configure postfix
- setup local mail delivery the usual way
- add procmail processing:
mailbox_command = procmail -a "$EXTENSION"
-
$ systemctl enable postfix
- send a test e-mail to address sms+12345@<yourserver>
- check if it is received in $HOME/Mailbox or /var/spool/mail/sms
- configure smstools
- edit /etc/smsd.conf, in my case the following section was enough:
[GSM1] device = /dev/ttyUSB0 init = AT^CURC=0 incoming = yes baudrate = 19200
-
$ service smstools restart
- test if SMS sending works by creating SMS:
$ cat << EOF > /var/spool/sms/outgoing/test To: +421903123456 test sms EOF
-
$ systemctl enable smstools
- edit /etc/smsd.conf, in my case the following section was enough:
- login as sms user
$ su sms
- create $HOME/.procmailrc file with the following contents:
# store mail in default folder and continue after that :0c ${DEFAULT} :0 | umask 000 ; $HOME/email-to-sms.py
- create $HOME/email-to-sms.py file with the following contents:
-
chmod +x email-to-sms.py usermod -a -G smsd sms
- edit email-to-sms.py to allow permitted senders
- 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? 🙂
upto step 7 it’s working fine. After that It does not work. Can you please help me out..
Are you able to send SMS as in step 6.3. ? What exactly doesn’t work?
yes ..
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.
Hi, nice work – I got similar ideas when creating a dbus wrapper for modemmanager.
https://github.com/maltegrosse/go-modemmanager
it only takes few lines of code to create a sms