As I have mentioned previously, Twitter has many uses. Today, I used it to implement a quick and simple solution for SMS alerts. A certain someone (a client of ours) wanted to receive an SMS message on his phone every time an email arrives to his mailbox. Sounds simple, right? Well, here in Cyprus we lack free and simple solutions for mass SMS messages. So, it wasn’t so simple until Twitter came along. Here is how I did.
I’ve registered two new accounts on Twitter (they are free, aren’t they?). One account is used for the client himself, and has his mobile configured, complete with “Don’t send SMS during these hours…” feature. The second account is used by the mail server to send notifications. Now, this second account is set to be protected in Twitter, so that only manually accepted people can follow and receive updates and notifications.
The script is designed to be used with mail aliases. For example, if I was to use for user@mysystem mailbox, I’d create the following aliases in /etc/aliases:
user: user,twitter twitter: "|/path/to/twit_mail.pl username password verbose"
The first line here tells the system to copy an incoming message to another account – twitter. This is needed so that the original email is received untouched by the user, and my twit_mail.pl script had something to play with.
The second line creates a pipe alias. Each message that comes to twitter@mysystem is piped to the twit_mail.pl script. The script requires two parameters – username and password for Twitter account to use – and allows for verbosity parameter. If verbose is set, then the script will send an informative status update to Twitter, something like “Message from email@example.com to user@mysystem about ‘some subject'”. If verbosity is off, a generic “You’ve got mail” will be sent.
You can easily find the appropriate lines in the script and change them for fixed values, if you only want to send notifications for one account. I chose to go with parameters, so that I could use the same copy of the script for several accounts.
Once you have the script set, aliases configured, and Twitter accounts created and linked, all you are left with is a test message. And that’s about it.