How to handle incoming email with Webhooks
As mentioned in the previous post, Teambox now supports incoming email with webhooks. This allows users to create conversations, answer notifications and comment on tasks by email.
This is a technical post, so you may want to skip it unless you’re a programmer.
About processing incoming email
If you are running an application server in Ruby on Rails, PHP, Java or Python, it can be hard to connect your web application to email servers.
Some applications like mailman allow you to connect incoming email servers to your application, but then you need your own email server.
How to receive email without setting up an email server
For this, we’ll be using Sendgrid’s email servers. Sendgrid not only allows you to send email, but also to set up an MX mail server that turns incoming emails into POST requests. POST requests can be then processed by your application to process email instantly.
This means that you can set up a route on your application, and Sendgrid will ping www.yourserver.com/process with the From, To, Subject and Body parameters of the email. Your application can then use its logic to turn that into emails.
This is the way it works:
- First we set up a Sendgrid account.
- Once we’re logged in, we visit http://sendgrid.com/developer/reply.
- We will be accepting every address like *@reply.yourapp.com. For this, enter “reply.yourapp.com” in Hostname and “http://yourapp.com/process” in URL.
- Good. Now we need to set up a DNS record that tells users that emails sent to whatever@reply.yourapp.com need to be sent to Sendgrid’s mail server. For this, open your DNS settings and create an MX record for “reply.yourapp.com.” pointing to “mx.sendgrid.net.”.
- Wait some hours for the DNS to propagate. You can check it with “host reply.yourapp.com”. If it returns “mx.sendgrid.net”, it means you can use it. (It may take up to one day for Gmail and others to accept the changes).
Now, whenever you send an email to that address, your application will receive a notifications. You can check this on the server logs.
Example code for receiving emails
This is an example Ruby on Rails snippet that could handle incoming email. For the sake of simplicity, I’m skipping the validations, which should return an error code to Sendgrid in case the parameters are malformed, not present or invalid.
def post_from_email
from = params[:from]
to = params


















Stay in touch
read ourblog contact us follow us
on Twitter