Why is my Heroku app not sending emails in product

2019-07-22 17:08发布

问题:

My devise emails work fine in development.

But now that I have pushed to Heroku and am using the sendgrid add-on, they don't get sent. I don't get an error. It seems like it is sent just fine, it is just that it never actually reaches my inbox.

This is my config/environment/production.rb file:

config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default :charset => "utf-8"
config.action_mailer.default_url_options = { :host => 'http://myapp.herokuapp.com' }

config.action_mailer.smtp_settings = {
  :user_name => ENV["SENDGRID_USERNAME"],
  :password => ENV["SENDGRID_PASSWORD"],
  :address => 'smtp.sendgrid.net',
  :domain => 'myapp.herokuapp.com',
  :port => 587,
  :authentication => :plain,
  :enable_starttls_auto => true
}

I checked those config vars on Heroku, and they return valid results.

Any ideas?

P.S. I don't have my domain pointing to the Heroku App yet, I just want to test it with the stock Heroku settings first.

回答1:

Everything look good, did you check if the sendgrid account is provisioned?

If you are on heroku, go to the sendgrid panel to finish the setup, just visit the app profile and under resources(which is the default) you should see the sendgrid add-on, click it and just make sure you have everything setup. In this case it will ask you to setup a template, but you can 'skip' this.

Hope this helps!



回答2:

This was happening to me too, or something like it. I was using the emails to only send to one email address, for my personal notifications.

It turns out that the email address "bounced" the first time and was being "suppressed" at Sendgrid for future sends. I would check the "suppressions" tab to make sure that's not happening to you.