views:

51

answers:

2

Hello, 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

+1  A: 

Just set environment variables on your development environment for SENDGRID_USERNAME, SENDGRID_PASSWORD, and SENDGRID_DOMAIN. Then it will work.

You can get the correct values for these from your Heroku app. Open heroku console and get the values of ENV['SENDGRID_USERNAME'] and so on.

Or just use a different set of SMTP settings locally. Or use sendmail or something.

tfe
Thanks, "use a different set of SMTP settings locally" that's exactly what I'm trying to learn how to do. What's the right way in Rails to do this setting across envs?
AnApprentice
I believe you can just set the `ActionMailer::Base.smtp_settings` in each of your environment initializer files (`config/environments/foo.rb`). I'm not exactly certain on the Rails Way here; I haven't configured mail in this way in a while.
tfe
I run several apps on Heroku with SendGrid, but I ran into the same issue (desiring to send mail locally as well as on Heroku). What I did was just go to SendGrid myself and sign up for an account. Then I had the username and password which I could set in the app for all environments, and those credentials weren't locked up inside the `ENV` of the Heroku app.
tfe
+1  A: 

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

joescharf