Take the 2-minute tour ×

I'm on Heroku, and emails don't get sent out in development, but are properly being sent in production. I'd like to run a seperate staging instance on Heroku, but don't want emails being sent out (just to a log).

share|improve this question
add comment

4 Answers

This line in test.rb tells ActionMailer not to deliver emails:

config.action_mailer.delivery_method = :test

Instead, they are accumulated in the ActionMailer::Base.deliveries array.

You'll need to set up a staging environment for your application and configure Heroku to use that environment on your staging instance.

share|improve this answer
add comment

Applications that use the Mail gem (including rails >= 3.0 projects) can use the safety_mailer gem. Specify a domain (or set of domains, or magic word in email address) email is allowed to go to, and email to all other domains is silently dropped.


Add the gem to your Gemfile, specifying groups (probably not production) to include it in.

gem "safety_mailer", :group => :development

Don't forget to bundle install to install

In your environment file config/environments/development.rb configure it, and some regular expressions.

config.action_mailer.delivery_method = :safety_mailer
SafetyMailer::Config.allowed_matchers = [ /mydomain.com/, /mytestacct@gmail.com/, /super_secret_test/ ]

... and now, email to anyone@mydomain.com, mytestacct@gmail.com, bob+super_secret_test@yahoo.com all get sent and email to other recipients (like the real users in the production database you copied to a test server) is suppressed.

share|improve this answer
add comment

You might be interested in mailtrap.io - that is a perfect tool to test email deliveries in development and production. All you have to do is set mailtrap.io as an smtp server in your staging environment config:

  config.action_mailer.smtp_settings = {
   :address => "mailtrap.io",
   :port => 2525,
   :authentication => :plain,
   :user_name => "LOGIN",
   :password => "PASSWORD"

Having this all your test emails sent in staging env will be stored in mailtrap for view and sharing. But non of them will be sent to the real addresses. You can use it in development as well. And by way - it's totally free!

share|improve this answer
Absolutely handy! Works beautifully. –  patrick-davey Oct 22 '12 at 6:34
Please disclose your pretty obvious affiliation. –  ThiefMaster Dec 9 '12 at 19:36
add comment

put this in your environment.rb file

config.action_mailer.delivery_method = :test

It should stop sending mail to the mail server, I think there is a :log option, but I have not tried it out.

share|improve this answer
You probably want it in a separate environments/staging.rb file, though, and not in the global environment.rb file. –  Robert Speicher Jun 17 '10 at 1:04
add comment

Your Answer


