As I have promised, I created a little ruby script which can easily be translated into Perl, PHP, or whatever language of your choosing. You are required to somehow pipe the e-mail to your script which there are various methods to do so, I will be explaining it using Dreamhost because that happens to be my current web host as of this writing.
Let’s get started
The Process:
What we are doing here is we are forwarding SMS messages (theres an option in your google voice settings) to your GMAIL account. On your GMAIL account you are going to then forward the message using a filter to a domain name e-mail address, which will then be piped to the script. The script is going to parse the raw email (convert raw data into something readable) and finally send it to your iPhone using the Prowl API (you will need to have the Prowl App installed on your iPhone).
No that we got that out of the way login to your Google Voice account and click on the Settings link. Then select the Voicemail and SMS tab. Under the Voicemail Notifications section check the box that says “Email the message to:“.
Logon to your GMAIL account and click on the Settings link select the Filters Tab and at the very bottom click the Create a new filter link. In the From Field enter the following:
*@txt.voice.google.com
Click on Next Step and Check the following boxes:
Skip the Inbox (Archive it)
Forward it to: THE DOMAIN EMAIL ADDRESS YOU WILL BE CREATING SOON
Delete it
You have successfully completed the easy part of this!
As I have mentioned before this guide will walk you through using Dreamhost as your hosting services. It can easily be done by other means with your host just send them an e-mail or try to follow the general idea of this guide Incoming Mail and PHP.
Login to your Dreamhost Panel and go into the Mail -> Manage E-Mail section. You are going to create an e-mail address using the email address you added to the GMAIL filter that is going to only forward mails to your server mail. What I mean by that is say I used in my GMAIL filter SMS@YOURDOMAIN.COM then create that same address in your Email panel on Dreamhost but select the option to only forward incoming mails to this address to your local server email. Your local server email address on Dreamhost is your username@server.com for example the server im on is jebediah.dreamhost.com then I’m going to use DREAMHOST-USERNAME@jebediah.dreamhost.com. You can easily get the server address by logging in using SSH it will be one of the lines that appears when you login.
Next thing we will need to do is create a file named .forward.postfix with the following contents and put it in your root directory:
Also create another file named .procmailrc with the following contents and put it in your root directory as well:
The only thing you need to know here is that the last three lines matches the forwarding e-mail address we created on your host and tells it to forward that incoming e-mail to the ruby script. The reason why we are matching for “X-Forwarded-To” is because we are forwarding from our GMAIL and therefore the e-mail address we created on our webhost wont appear in the “To” field of the raw e-mail.
The Ruby script is very plain and simple create a file named mail.rb and put it the root folder or wherever you wish to just as long as you are properly specifying its full path in the .procmailrc file, with the following contents:
The script is pretty straight forward we are using the TMAIL gem and the Prowly gem. The Tmail gem basically takes the STDIN input (the raw email) and parses it to something more usable to send to the Prowl API.
Of course this is a one user scenario, if you wish to support multiple users and higher volumes you may want to look into using other means. I originally created a similar version of this script in PHP which just grabs the raw data and performs a post request to another script in order to keep things to a minimum on the piped script.
Once you have the raw e-mail parsed you can basically do anything you want. You can match the mail.to e-mail address to a local database and extract the Prowl API from there to support multiple users. Or even go a step further and send the message to your GTALK by creating a simple XMPP bot. This script is very much open source, do as you wish with it. I’m pretty new at writing things in ruby so if you have yet a more efficient way of doing this please let me know.
Useful resources:
http://www.evolt.org/incoming_mail_and_php
http://tmail.rubyforge.org/
http://prowl.weks.net/api.php
http://github.com/rafmagana/prowly

