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

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


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.


If it works in development mode, then it will work in production mode.

Supposing everything is setup correctly, resetting a password in development will already send an actual email using your gmail account.

Devise only relies on the mailer config setup correctly (which you have done), and configuring devise to allow password reset, and possibly another setting for the From field of the email.


This should work fine!

As long as config/environments/production.rb has the same thing with an exception. The default_url_options should have a :host value of 'localhost' only in development and 'YOURAPPNAME.herokuapp.com' in heroku production.

i.e.

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

Remember to unlock captcha on gmail, otherwise it won't send email from heroku (unknown source). You can do that by going to this link: http://www.google.com/accounts/DisplayUnlockCaptcha

Just as a suggestion, I'd say move this from environments.rb

ActionMailer::Base.perform_deliveries = trueActionMailer::Base.raise_delivery_errors = true

and place is in environments/development.rb as

config.action_mailer.perform_deliveries = trueconfig.action_mailer.raise_delivery_errors = true

It's not needed in production.

See Net::SMTPAuthenticationError when sending email from Rails app (on staging environment) for more information in regards to gmail seeing heroku as an unknown host.