Clicky

HOWTO send email with Rails & Mailgun

Mailgun is a service which provides a set of APIs for sending, receiving, and tracking email. This guide will show you how to setup your Rails application to send email via Mailgun with just three lines of code.


First step, add the mailgunner gem to your Gemfile (and run bundler to install):

gem 'mailgunner', '~> 2.4'

Then you need to configure ActionMailer to use mailgunner by adding a couple of lines to config/environments/production.rb:

config.action_mailer.delivery_method = :mailgun
config.action_mailer.mailgun_settings = {domain: 'app123example.mailgun.org'}

That’s it. You can then use ActionMailer to create and deliver emails, and in production they will be delivered via Mailgun!


New to ActionMailer? Start with the Rails guide.

Using the Mailgun Heroku addon? You don’t need the second configuration line for specifying the domain explicitly, it’ll pick that up automatically.

Looking for an alternative service to Mailgun? Try Amazon SES or Postmark.

Need to debug emails in development? Try mailcatcher.