Lupine Software Development

Sending Gmail through SMTP on Heroku, Rails 3

by LupineDev

Heroku's documentation for sending smtp email from your Rails app is pretty thurough but when it comes to Rails 3 and gmail via smtp it's a little out dated.  Mikel Lindsaar made a super-duper blog post on sending email with gmail/smtp from a Rails 3 application.

I would follow his instructions for testing your configuration settings in the rails console.  After that it's just  a few simple steps.

First put your smtp settings in an initializer....

# config/initializers/gmail.rb
ActionMailer::Base.smtp_settings = {
  :address              => "smtp.gmail.com",
  :port                 => 587,
  :domain               => 'your.host.name',
  :user_name            => '<your_username>', # full email address (user@your.host.name.com)
  :password             => '<your_password>',
  :authentication       => 'plain',
  :enable_starttls_auto => true
}

Also add default_url_options in the production environment.

# config/environments/production.rb
YourRailsApp::Application.configure do 
  ...
  config.action_mailer.default_url_options = { :host => 'your_app.heroku.com' }
  # Disable delivery errors, bad email addresses will be ignored 
  ...
end

After that you should be good to go :)