automatically sending text messages from email messages

Using the natty little webtext script (updated to use an $HOME/.webtextrc file for the username/password) and a little bit of procmail magic, we can now send messages containing the subject line of a specific email message once it has been received.
Firstly, there’s the .procmailrc file. The recipe I’m using looks like:

# send text messages
:0 W
* ^subject: IM:
| $HOME/bin/sendim

The script sendim is a simple bash script that checks the subject line contains “IM: ” and then sends on the remainder of the subject line as a text message to my mobile phone.
As a security precaution, I’ve added a special header ‘X-apikey’ which is checked by the sendim. If the apikey doesn’t match then the rule doesn’t fire. You should replace the XXX item with your own value generated using echo <some text here> | sha1sum. By not putting the api check in the .procmailrc file you can quietly drop messages that don’t have the correct key instead of keeping them in your inbox.

#!/bin/bash -p

export PATH=$HOME/bin:$PATH

subject=
apikey=
apikey_c="XXX"

while read foo; do
    [[ -z $foo ]] && break
    subject=${subject:-$(echo $foo | sed -n "s/[sS]ubject: IM: //p")}
    apikey=${apikey:-$(echo $foo | sed -n "s/X-apikey: //p")}
done

if [[ -n $subject && $apikey = $apikey_c ]]; then
    webtext -t YYY "$subject" >/dev/null 2>&1
fi

Source of sendim. Don’t forget to replace the XXX and YYY with your chosen items.

One Reply to “automatically sending text messages from email messages”

Comments are closed.