I love me some Heroku. If you’ve never heard of Heroku, it’s an awesome Ruby on Rails hosting company. It makes deploying and hosting rails apps an absolute breeze.
Anyway, I wanted my newest creation, www.SaleTrap.com, to read incoming emails and respond to them. After poking around the Heroku mailing list, and reading the documentation, I ran across this – http://wiki.sendgrid.com/doku.php?id=parse_api, but no step by step instructions on how to get it working. So without further ado, here’s a step-by-step guide on how to get your Heroku rails app to read incoming email.
- Create your rails app on Heroku. Duh.
- Add the sendgrid add on to your app.
- Create a controller to read the incoming email post. For example:
- Now starts the fun part. Fire up your command line, and go to the /app directory of your app. type in “heroku config –long”. It will return your sendgrid username and password
- Awesome, now venture over to www.SendGrid.com and login with those credentials. Go to the “develoeprs” tab, then the “parsing incoming” sub tab (url will be http://sendgrid.com/developer/reply)
- Alright. Time to get tricky. The first part is easy – set the url to your controller action above.
- The second part is a bit more complex – you can’t specify a single email address in sendgrid, so you have to have all emails for your domain, or a chosen subdomain hit the parse api. In this example, I’ve chosen “watch.saletrap.com”.
- Once you have your subdomain, enter it into sendgrid. Phew, your work is done here.
- Now, on to your DNS provider. I use GoDaddy, but this should work with whatever. Go to your DNS control, and enter a MX record, using your subdomain (i.e. “watch” in this case), as the host, and “mx.sendgrid.net” as the destination.
- Still with me? Good. Now on to the email address. I set up an email forwarding account for SaleTrap.com with GoDaddy, with the “email@example.com” address, that points to firstname.lastname@example.org. Get the key point there? The email points to the watch.saletrap.com, and we have an mx record for “watch” that points at sendgrid, so hence, our emails magically get sent to sendgrid, which posts pack to the url in our rails app that we specified.
- And there you have it, you can now accept incoming emails into your rails app using heroku and sendgrid.
Want to see it in action? Do the following:
- Go to www.JCrew.com, and choose an item you like.
- Copy the url of that item (e.g.http://www.jcrew.com/AST/Browse/MensBrowse/Men_Shop_By_Category/shoes/casualbootschukkas/PRDOVR~20525/20525.jsp), and email it to email@example.com
- Wait 30 seconds, and refresh your inbox. Enjoy
DISCLAIMER: www.SaleTrap.com is far from complete yet, so don’t expect too much at this point. It’s still under active development, so will probably be buggy.
I want to send a HUGE thank you to Isaac at SendGrid for helping me out. He, and SendGrid, rock.