---
title: Deliver Email With Amazon SES In A Rails app
teaser: How to send email from a Rails app to Amazon SES.
tags: web,rails
author: Dan Croak
published_on: 2011-02-04
---

[Amazon SES](http://aws.amazon.com/ses/) came out last week and... you know...
shiny.

## Why use Amazon SES

Right now, price. At our current email rates, we would save more than $10,000
in 2011 using Amazon SES over SendGrid for [Airbrake](http://airbrake.io).

However, SendGrid's a reliable entity with more features (analytics, spam
reports, etc.) so even with those savings, we're leaving SendGrid yet on
Airbrake.

In the meantime, we're trying Amazon SES on another project that is in private
beta to see how well it performs in terms of deliverability, blacklisting, etc.

## Open source library

A week after Amazon announced the service, there were plenty of libraries on
Github for Amazon SES. I chose
[drewblas/aws-ses](https://github.com/drewblas/aws-ses) (the [aws-ses
gem](http://rubygems.org/gems/aws-ses)).

## Comparing SendGrid implementation in a Rails app

How to use SendGrid in a Rails app:

```ruby
MyRailsApp::Application.configure do
  config.action_mailer.smtp_settings = {
    address: ENV['SMTP_ADDRESS'],
    authentication: :login,
    domain: 'staging.myrailsapp.com',
    password: ENV['SMTP_PASSWORD'],
    port: 25,
    user_name: ENV['SMTP_USERNAME']
  }
end
```

You don't need a special gem: it's just SMTP.

## Using the aws-ses gem in a Rails app

Amazon SES requires some [HMAC](http://en.wikipedia.org/wiki/HMAC)'ing and
other stuff, but when using a library, it's still pretty easy and it has the
same dependencies as Rails.

Add the gem to your Gemfile:

```ruby
gem 'aws-ses', '~> 0.4.4', require: 'aws/ses'
```

Extend ActionMailer in `config/initializers/amazon_ses.rb`:

```ruby
ActionMailer::Base.add_delivery_method :ses, AWS::SES::Base,
  access_key_id: ENV['AMAZON_ACCESS_KEY'],
  secret_access_key: ENV['AMAZON_SECRET_KEY']
```

Set the delivery method in `config/environments/{staging,production}.rb`:

```ruby
config.action_mailer.delivery_method = :ses
```

That'll do it. Happy emailing!
