---
title: Griddler is Better Than Ever!
teaser: 'Griddler has some useful new features, and we''ve updated our installation
  and configuration instructions.

  '
tags: news,web,rails,griddler,open source
author: Gabe Berke-Williams
published_on: 2015-07-24
---

[Griddler][griddler] is a Rails engine that provides an endpoint for common
email services and hands off the email to your application. You can configure
[Mailgun][] (or whatever you're using) to POST emails to your Rails app to handle
incoming email from your users.

[griddler]: http://griddler.io/

Our [old Griddler announcement post][old] now has outdated instructions with the
changes in [Griddler] 1.0.0,
which means Griddler deserves a new post.

[old]: https://thoughtbot.com/blog/handle-incoming-email-with-griddler

## Setup

Let's walk through setting up Griddler with [Mailgun].
The instructions are almost exactly the same
for other adapters like [Mandrill] or [Sendgrid],
though you should read the documentation for each adapter to make sure.

[Mailgun]: http://www.mailgun.com
[Mandrill]: https://www.mandrill.com
[Sendgrid]: https://sendgrid.com

First add the adapter to your Gemfile, which will bring in Griddler with it:

```ruby
# Gemfile

gem "griddler-mailgun"
```

The Griddler README has [a list of all available adapters][adapters].
[adapters]: https://github.com/thoughtbot/griddler#adapters

You must configure Griddler to use your adapter:

```ruby
# config/initializers/griddler.rb

Griddler.configure do |config|
  config.email_service = :mailgun
end
```

## Routes

Now you need to set up a route that your email service can POST to.
You have a few options:

```ruby
# config/routes.rb

# mount using default path: POST /email_processor
mount_griddler

# or, mount using a custom path: POST /email/incoming
mount_griddler "/email/incoming"

# or, the DIY approach:
post "/email_processor" => "griddler/emails#create"
```

Once your adapter POSTS to your endpoint, Griddler will pass a `Griddler::Email`
object to a class called `EmailProcessor` that you create:

```ruby
class EmailProcessor
  def initialize(email)
    @email = email
  end

  def process
    # all of your code to deal with the email goes here
  end
end
```

The `email` object has [a lot of attributes][attributes], but here are the ones
you'll likely use most:

[attributes]: https://github.com/thoughtbot/griddler#griddleremail-attributes

* `to`
* `from`
* `subject`
* `body`
* `raw_body`

## Configuration

Let's say you want to configure Griddler to use a `Mailman` class like this,
rather than an `EmailProcessor` class:

```ruby
class Mailman
  def initialize(email)
  end

  def handle_it
  end
end
```

You need to add a few lines to your Griddler initializer:

```ruby
# config/initializers/griddler.rb

Griddler.configure do |config|
  config.email_service = :mailgun

  config.processor_class = Mailman
  config.processor_method = :handle_it
end
```

There are more [configuration options][configuration] in the README.

[configuration]: https://github.com/thoughtbot/griddler#configuration-options

## Let your users interact with your app via email

If an email has `-- Reply ABOVE THIS LINE --` in it, then Griddler provides
everything above that delimiter in the `body` attribute on the `email`. If the line
isn't there, then `body` has everything in the body, as you'd expect.

This lets you grab people's replies to an email thread
without the clutter of past responses,
like [Basecamp]. If you really need the whole body, you can use `raw_body`.

[Basecamp]: https://basecamp.com

For more information on Griddler, including how to change the reply delimiter,
check out [the Griddler website](http://griddler.io).
