How to set up mailer in Rails app for production environment on Heroku

banditKing picture banditKing · Aug 17, 2012 · Viewed 17.4k times · Source

I need to use a mailer for sending out emails to users to set their passwords to the "recoverable" function of Devise and active admin. On the development environment I have done this by adding the following to these files:

config/environments/development

#Added per active admin install instructions
config.action_mailer.default_url_options = { :host => 'localhost:3000' }


#These settings are for the sending out email for active admin and consequently the   devise mailer
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.smtp_settings = 
{

  :address            => 'smtp.gmail.com',
  :port               => 587,
  :domain             => 'gmail.com', #you can also use google.com
  :authentication     => :plain,
  :user_name          => '[email protected]',
  :password           => 'XXXXXXX'
}

How do I get the same functionality for the production environment? I want to deploy my app to Heroku. What files and code would I need to add?

Answer

steel picture steel · May 27, 2014

All configurations you have set in Development mode will work EXCEPT you will need to reconfigure the default mailer url.

So.

  1. Copy-paste your settings from development.rb.

  2. Point your default mailer to your heroku app:

    config.action_mailer.default_url_options = { :host => 'YOURAPPNAME.herokuapp.com' }
    

Also, be careful of any email limits your smtp may have when moving to production. It's hard to trigger gmail's smtp limits while developing, for example, but they could be more easily triggered in production.