Heroku设置SendGrid麻烦
问题描述:
我一直有这个问题,因为faaarrrrr太久了。我已经看过类似于我的无数问题,似乎无法让他们工作。Heroku设置SendGrid麻烦
我一直在使用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文件中的一个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网站它不具有任何活动都不要求或反弹。所以我认为我的配置有问题。
任何帮助将不胜感激我失去了我的想法。
******更新*******
这是我现在的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不喜欢被推动分支,所以它一直都是正确的。
我最终不得不与主人合并,并推动主人heroku使其工作。
有许多方法可以将分支推送到heroku,但是我很难让它工作,即使指定了我想推送并运行分支。
我希望这可以节省一些人在未来的时间。
如果需要更多信息,请告诉我,我会为您解决。 – Stockster
'user_name'和'password'应该是你的Sendgrid用户名和密码。您还应该将它们设置为环境变量而不是硬编码它们,因为除非您的存储库是私人的,否则他们将可以被其他人查看。 如果你没有收到错误消息可能没有被发送,所以我会检查你的user.rb文件。 – domi91c
我的问题是我可以在开发环境中发送电子邮件,但是当我推送到heroku时,它不会发送。我知道或至少高度怀疑这是与域名/端口信息有关,但无法为我的生活弄清楚。 – Stockster