11

I've got a simple Rails 3.2.7 app with Devise added that is deployed to Heroku with Sendgrid added. It works fine on heroku for everything except when it needs to do a password retrieve which requires sending an email. From all the posts i have read i suspect i am somehow setting up the mail parameters incorrectly. Any suggestions are appreciated.

For config/environments/production.rb i added

config.action_mailer.default_url_options = { :host => 'smtp.sendgrid.net'} 

for config/initializers/devise.rb i added

config.mailer_sender = "mail-to-send@from.com"

and for config/environments.rb i added

ActionMailer::Base.smtp_settings = {
:address        => 'smtp.sendgrid.net',
:port           => '587',
:authentication => :plain,
:user_name      => ENV['SENDGRID_USERNAME'],
:password       => ENV['SENDGRID_PASSWORD'],
:domain         => 'heroku.com',
:enable_starttls_auto => true
}
Swift
  • 13,118
  • 5
  • 56
  • 80
user2284821
  • 433
  • 6
  • 16

1 Answers1

8

So, your problem is you were referencing the wrong environment variables. Heroku stores your SendGrid credentials in ENV['SENDGRID_USERNAME'] and ENV['SENDGRID_PASSWORD']. You were using your actual username and password as the key names.

This will work:

ActionMailer::Base.smtp_settings = {
  :address        => 'smtp.sendgrid.net',
  :port           => '587',
  :authentication => :plain,
  :user_name      => ENV['SENDGRID_USERNAME'],
  :password       => ENV['SENDGRID_PASSWORD'],
  :domain         => 'heroku.com',
  :enable_starttls_auto => true
}
Swift
  • 13,118
  • 5
  • 56
  • 80