Rails ActionMailer with SendGrid

AnApprentice picture AnApprentice · Oct 18, 2010 · Viewed 8.1k times · Source

I'm using SendGrid to send emails on Heroku...

The problem so far is while it works great on Heroku, on my local host it fails.

Right now I have SendGrig install here, config/setup_mail.rb:

ActionMailer::Base.smtp_settings = {
  :address        => "smtp.sendgrid.net",
  :port           => "25",
  :authentication => :plain,
  :user_name      => ENV['SENDGRID_USERNAME'],
  :password       => ENV['SENDGRID_PASSWORD'],
  :domain         => ENV['SENDGRID_DOMAIN']
}

What's a Heroku/SendGrid way to allow me to make sure my mailers work in DEV. Is this setup_mail.rb file a good thing? Should it be in the env file? Any other thoughts?

Thanks

Answer

joescharf picture joescharf · Oct 18, 2010

Using config/environments/[development.rb | production.rb] as tfe mentioned above sounds like its the way to go. Just put the ActionMailer configuration in either of those files and change it to suit the development|production environment.

You can also find your SendGrid credentials used by Heroku by issuing the following command:

heroku config --long

These credentials are used for all SendGrid authentication (SMTP Auth, Website login to view stats, etc., API access)

-- Joe

SendGrid