Mandrill has been the go-to mailer addon for Heroku apps for many people. However, MailChimp is consolidating their offerings and ending Mandrill support shortly. Existing Mandrill users have until April 27, 2016 to switch to a new provider. In this guide I’ll go over two alternatives I’ve used in the last couple months; SendGrid, and Amazon SES.
SendGrid
Overview
SendGrid’s app has existed for some time, but in my experience had always taken a backseat to Mandrill. Now, with Mandrill gone, they’re hustling hard to get Mandrill’s previous marketshare. They’ve been solid and timely in my experience with them over the last month.
Setup
SendGrid has you covered as a Heroku addon. Just search for it and add the appropriate tier on to your app, then make the following config changes, and you’re good to go.
config/environments/production.rb
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => 'smtp.SendGrid.net',
:port => '587',
:authentication => :plain,
:user_name => ENV['SendGrid_USERNAME'],
:password => ENV['SendGrid_PASSWORD'],
:domain => 'heroku.com',
:enable_starttls_auto => true
}
Heroku will automatically set the appropriate envrionment variables, so after you put the above block in your config, you’re done. If you’re doing this on a different server, simply set your environment variables to the appropriate credentials that SendGrid provides you with.
Amazon SES
Overview
Amazon’s been rolling out computing services like a madman over the last few years. Visit the AWS site and look at everything. There’s a lot there, and tons of companies and individuals trust and use Amazon for their computing and server needs. In fact, many enterprise Rails job postings mark AWS knowledge as a requirement for applications. A major bonus to SES is that if you’re running your server on EC2 or Elastic Beanstalk, your first 62,000 messages won’t be charged to your account.
Setup
Gemfile
gem 'aws-sdk', '~> 2'
gem 'aws-sdk-rails'
bundle install
those two gems, and then add the following configuration to your app.
config/environments/production.rb
aws_credentials = Aws::Credentials.new(ENV['AWS_ACCESS_KEY_ID'], ENV['AWS_ACCESS_KEY_ID'])
Aws::Rails.add_action_mailer_delivery_method(:aws_ses, credentials: aws_credentials, region: ENV['AWS_REGION'])
config.action_mailer.delivery_method = :aws_ses
You’ll need to set the appropriate environment variables, AWS_ACCESS_KEY_ID
, AWS_ACCESS_KEY_ID
, and AWS_REGION
for this to work properly. Get those from your AWS account and set the correct region. The last line tells actionmailer to use the :aws_ses
delivery method, which is provided courtesy of aws-sdk-rails
.
Final Thoughts
If you’re making a switch from Mandrill, I’d highly recommend using either one of these solutions. I haven’t used them in a high volume application yet, but they’ve both served great and send email and attachments in a timely manner. Remember to do benchmarking and some cost analysis for your specific app if you’ll push on the edge of the free tier for either of these. For Heroku users that want to get up and running with a test app or small personal project, go with SendGrid. If you’ve already got an AWS account or will be migrating to any AWS products in the future or simply want to dip your toes in the AWS pool, then give SES a shot. I’ve been extremely impressed with the timeliness of their delivery so far.
Nathaniel Rowe is one of LD Studio’s Rails developers. Check out his site at http://blog.nrowegt.com/ for more Rails based blog posts.