Heroku 设置 SendGrid 麻烦

Heroku setting up SendGrid trouble

我已经为这个问题困扰太久了。我已经看过无数与我类似的问题,但似乎无法让其中任何一个发挥作用。

我一直在使用 cloud9 ide 并推送到 heroku 尝试使用 SendGrid 发送一封简单的电子邮件。我很确定问题出在 production.rb 中的设置中,或者出在我使用 SendGrid 设置 heroku 的方式中,但我无能为力。

config.action_mailer.default_url_options = { :host => 'http://tranquil-plateau-41839.herokuapp.com' }

我已将其放入环境文件夹中的 production.rb 文件中。

UserMailer.welcome_email(@user).deliver_now

这是我的 user.rb 文件中的 inside 如果用户保存则执行的 if 语句。我已经尝试了一百万种不同的组合来让它发挥作用,但它似乎并不想这样做。

这是我从 heroku -logs 得到的

2017-11-18T04:40:06.396183+00:00 app[web.1]:    (2.1ms)  COMMIT
2017-11-18T04:40:06.396635+00:00 app[web.1]: Completed 302 Found in 140ms (ActiveRecord: 37.3ms)
2017-11-18T04:40:06.396468+00:00 app[web.1]: Redirected to http://tranquil-plateau-41839.herokuapp.com/login
2017-11-18T04:40:06.459084+00:00 app[web.1]: Started GET "/login" for 173.28.213.164 at 2017-11-18 04:40:06 +0000
2017-11-18T04:40:06.460969+00:00 app[web.1]: Processing by SessionsController#new as HTML
2017-11-18T04:40:06.462953+00:00 app[web.1]:   Rendered sessions/new.html.haml within layouts/application (1.1ms)
2017-11-18T04:40:06.464328+00:00 app[web.1]: Completed 200 OK in 3ms (Views: 2.7ms | ActiveRecord: 0.0ms)
2017-11-18T04:40:06.465391+00:00 heroku[router]: at=info method=GET path="/login" host=tranquil-plateau-41839.herokuapp.com request_id=e079f0c1-4408-4c29-b4a0-0707004e02fc fwd="173.28.213.164" dyno=web.1 connect=0ms service=10ms status=200 bytes=2823 protocol=http
2017-11-18T04:40:06.397638+00:00 heroku[router]: at=info method=POST path="/users" host=tranquil-plateau-41839.herokuapp.com request_id=f851ddf6-d55a-43b9-9631-a17e98fa47a4 fwd="173.28.213.164" dyno=web.1 connect=0ms service=147ms status=302 bytes=1064 protocol=http

它似乎没有出错,当我查看我的 SendGrid 网站时,它没有任何 activity 甚至没有请求或退回。所以我假设我的配置有问题。

任何帮助将不胜感激我正在失去理智。

****** 已更新 *******

现在这是我的 production.rb 文件

config.action_mailer.default_url_options = { host: "http://tranquil-plateau-
    41839.herokuapp.com" }
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.default :charset => "utf-8"
  config.force_ssl = true
  config.action_mailer.smtp_settings = {
    :address => 'smtp.sendgrid.net',
    :port => 587,
    :domain => 'heroku.com',
    :user_name => 'app***@heroku.com',
    :password => 'secret',
    :authentication => :plain,
    :enable_starttls_auto => true
  }

这是我的 development.rb 文件

config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { host:'localhost', port: '3000'}
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default :charset => "utf-8"
config.action_mailer.smtp_settings = {
    :address => "smtp.sendgrid.net",
    :port => 2525,
    :domain => 'localhost:3000',
    :user_name => 'app****@heroku.com',
    :password => 'secret',
    :authentication => :plain,
    :enable_starttls_auto => true
}

我强烈感觉到我的域或端口是生产中的问题。但是,在开发过程中,电子邮件成功通过。我已经尝试了一百万种不同的变体,但我似乎无法弄明白。

其实我自己想出来了。问题是 Heroku 不喜欢被推送分支,所以它实际上一直都是正确的。

我最终不得不与 master 合并并将 master 推送到 heroku 以使其工作。

有很多方法可以将分支推送到 heroku,但是我无法让它工作,即使指定我想要推送和 运行 一个分支。

我希望这能在将来节省一些时间。