textme.py: Have important emails come in as text messages (for free!)

It’s sometimes more relaxing to forward texts from certain people to your cell phone as text messages, rather than compulsively checking your email or being notified by the stupid iPhone new mail sound of every spam message you get.

textmeI’ve uploaded a Python script here that does just that. It’s in zip format because I’ve also bundled the necessary Python dependencies with it since it can be tricky sometimes installing your own in Python (twilio-pythonsix, and httplib2). If you already have these or prefer to install them yourself, you can just download the Python script by itself here.

This script logs you in to Gmail and checks your email every 10 seconds. If the from field of a new email matches a string that you specify, it sends you a text message including the sender, subject, send time, and first 100 characters of the email.

How to make it work ASAP (note: requires making a free account on a web texting service, but it’s quick, free, and better yet hip):

  1. Download the script and dependencies I referenced above.
  2. Sign up for a free trial account at https://www.twilio.com. I think you may have to provide a credit card number, but I’ve had an account there for a while, and they seem like a respectable company (they’ve never charged me). Of course, you may decide you really like this and want to pay them a few cents per text message to remove the note on each message that it was sent from a Twilio trial account (it doesn’t bother me).
  3. Fill in the following lines at the top of the script. The first three you’ll get from making your Twilio account, the next two are your Gmail login info to check your inbox every 10 seconds, then put in the cell number you’d like the free text messages to go to and the regular expression pattern to search the from field for in order for it to send the message. [tip: to forward messages from Bob B and Jane J, put pattern = “Bob B|Jane J”; the middle character is a pipe, found above the return key, and means “or”].

ACCOUNT_SID = “your twilio id”
AUTH_TOKEN = “your twilio token”
twilionum = “your twilio phone nmber”
username = “your gmail username”
password = “your gmail password”
cellnumber = “the number you want to receive text messages at, eg 2038675309”
pattern = “regular expression (aka pattern, eg a name) to search the from field”

  1. Launch the script by changing to the directory where textme.py is, and type python textme.py. It should continue running and sending you text messages until the process is terminated and/or the computer goes to sleep or restarts. So, it’s probably easiest to have this running somewhere on a server that you know won’t restart for a while.
  2. I hope it’s helpful! As always, email with questions or comments.