How to setup an email to SMS forwarding gateway address with Postfix

SMS is an important tool in the arsenal I use to fight my never-ending war with productivity-destroying distractions.

Colleagues, friends, mailing lists, foes, viagra peddlers and nigerian princes send me in aggregate about 300 pieces of of e-mail every day, most of it not really that important. All of this noise can eat up an enormous amount of my attention so when I really need to concentrate I'm pretty much forced to ignore e-mail altogether for sometimes weeks at a time.

By comparison I only receive less than 10 SMS messages a day on my phone. They're also much shorter so I can go over them much more quickly. Consequently, it's usually much easier to get my attention with an SMS than an e-mail so people who know me have learned to use SMS as an out-of-band high-priority communication channel.

OTOH, I realize sending an SMS when you're busy hacking away at your computer can be a bit of a bother. You have to get out your phone, and fiddle around with a crappy virtual keyboard, etc.

So to get the best of both worlds I setup a secret email address on my mail server that sends e-mails directly to my phone as SMS. This address I give out to anyone who really needs to get in touch with me even when I'm offline.

This is implemented as a configuration on my postfix mail server, which pipes any email sent to a particular secret alias through to the script, which extracts the body of the message, and then to a little script which sends the body of the message to clickatell, a company that provides a simple SMS sending API.

Let's take a look behind the scenes:

# grep sms /etc/postfix/aliases
sms.c2e1: "|/usr/local/bin/|/usr/local/bin/clickatell-sendmsg --stdin to=0541232123 --maxlen=140"

# cat /usr/local/bin/clickatell-sendmsg

export CLICKATELL_USER=liraz
export CLICKATELL_PASSWORD=mypassword
export CLICKATELL_API_ID=1232123

exec $(dirname $0)/ "$@"

I'm attaching the required scripts to the end of this post.


  • Clickatell's HTTP/HTTPS API can be easily invoked via curl

  • is a 133 line python wrapper around curl

  • is a is a 11 line wrapper that extracts the message body from an email that postfix pipes through to these aliases.

    Also, if a PGP signature exists it will delete it.

Add new comment