We're working on something new! Hook Relay gives you Stripe-quality webhooks in minutes. Sign up for free today!

Handle Inbound Email in any Rack Application

We built Incoming for Honeybadger to streamline discussions about errors. For example, you can comment on any error just by replying to the notification. Most of our comments come in this way, so we consider it a big win.

So your client just called...

He wants his app to handle incoming email. Just like Basecamp.

No problem, you think, lots of services will send you email by POST to your app. Should be easy. Right?


Each service uses a proprietary format. Some send you the parsed email, some send it raw. Some send an authentication signature. Some don't.

Wouldn't it be nice if you could skip this part, and work with standard (well-known) ruby objects?

Wouldn't it be nice if you could change vendors...without rewriting your code?

If you're using Incoming!, you can.


Incoming! takes a Rack::Request and gives you a Mail::Message

Supported Services

Incoming supports these great services:

  1. SendGrid

  2. Mailgun

  3. Postmark

  4. CloudMailin

  5. Actual mail servers you run yourself (woah)

Best of all, it's easy to extend. So it's already compatible with services that don't even exist yet! (not really, but kind of)

So why do I want inbound email?

Giving people an option to do something by sending you an email makes them more likely to do it.

We built Incoming! for honeybadger.io. We needed a way to streamline discussions about errors. For example, you can comment on any error just by replying to the notification. Most of our comments come in this way, so we consider it a big win.

As of this writing, the gem has been used internally by the Honeybadger team for about six months.

Show me the code!

Here's a simple example using CloudMailin.

`# First, you define an email receiver class
class EmailReceiver < Incoming::Strategies::CloudMailin
  def receive(mail)
    puts %(Got message from #{mail.to.first} with subject "#{mail.subject}")

# Then you feed it a Rack::Request object. And you're done. 
req = Rack::Request.new(env)
result = EmailReceiver.receive(req) # => Got message from whoever@wherever.com with subject "hello world"

For more detail, check out the Readme.

But how do you use it in Rails?

Using Incoming! in rails is just as easy. Let's build a sample app.

REQUIREMENT: I hate texting. It's just a peeve of mine. But I need to be able to send love notes to my fiancee while she's in class.

Obviously, the answer is to build an email-to-sms bridge!

First, we set up our email receiver:

`# app/email_receivers/incoming.rb
class EmailToSmsReceiver < Incoming::Strategies::Postmark
  def receive(mail)
    send_sms([mail.subject, mail.body].join(": "))
    def send_sms(message)
      # Insert twilio magic here

Second, we add a controller to pipe requests into our receiver:

`# app/controllers/emails_controller.rb
class EmailsController < ActionController::Base
  def create
    if EmailToSmsReceiver.receive(request)
      render :json => { :status => 'ok' }
      render :json => { :status => 'rejected' }, :status => 403

Oh yeah, we need a route:

`# config/routes.rb
Rails.application.routes.draw do
  post '/emails' => 'emails#create'

That's it.

How does Incoming! compare with other gems?

There are other gems in this space. Most notably Thoughtbot's Griddler.

However there are a few places where Incoming! stands out. It:

  1. Supports multiple mail services

  2. Works with any rack application, not just rails

  3. Hands you a standard Mail::Message

  4. Doesn't make assumptions about your use case

Do you have a meme pic for me?

Yes, yes we do.


Honeybadger has your back when it counts.

We're the only error tracker that combines exception monitoring, uptime monitoring, and cron monitoring into a single, simple to use platform. Our mission: to tame production and make you a better, more productive developer.

Learn more
author photo

Starr Horne

Starr Horne is a Rubyist and Chief JavaScripter at Honeybadger.io. When she's not neck-deep in other people's bugs, she enjoys making furniture with traditional hand-tools, reading history and brewing beer in her garage in Seattle.

More articles by Starr Horne
“We've looked at a lot of error management systems. Honeybadger is head and shoulders above the rest and somehow gets better with every new release.” 
Michael Smith
Try Error Monitoring Free for 15 Days