Ruby on Rails 中的 Sendgrid/电子邮件发送问题(托管在 Heroku 上) [英] Sendgrid / email sending issues in Ruby on Rails (hosted on Heroku)

查看:32
本文介绍了Ruby on Rails 中的 Sendgrid/电子邮件发送问题(托管在 Heroku 上)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 authlogic 进行身份验证并部署在 heroku 上的 rails 3.1 应用程序上让 sendgrid 成功发送电子邮件时遇到问题.我在 config/environments/[development.rb 和 production.rb] 上有以下操作邮件程序配置:

im having a problem getting sendgrid to send emails successfully on a rails 3.1 app that's using authlogic for authentication and is being deployed on heroku. i have the following action mailer configuration on config/environments/[development.rb and production.rb]:

config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.default_charset = "utf-8"
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
config.action_mailer.smtp_settings = {
  :address => 'smtp.sendgrid.net',
  :port => 587,
  :domain => ENV['SENDGRID_DOMAIN'],
  :user_name =>  ENV['SENDGRID_USERNAME'],
  :password => ENV['SENDGRID_PASSWORD'],
  :authentication => 'plain',
  :enable_starttls_auto => true
}

对于production.rb,除了

for production.rb, the above code is the same except for


    config.action_mailer.default_url_options = { :host => [app name in heroku] }

当我在开发模式下运行时,报告了以下错误:

when i run it development mode, i get the following error reported:


    Completed 500 Internal Server Error in 21740ms
    Net::SMTPFatalError (550 Cannot receive from specified address notification@[app-domain]: Unauthenticated senders not allowed
):

我现在真的不知道如何设置才能让它工作.有没有在 heroku 和 rails 上设置 sendgrid 的经验的人知道发生了什么?

i now dont really know how to set it up to get it working. does anyone with some prior experience on setting up sendgrid on heroku and rails know what's going on?

非常感谢.你们是最棒的!!!

thank you so much. you guys are the best!!!

推荐答案

我在这个问题上花了半天时间,现在终于让我的工作了.非常沮丧,因为它是由于糟糕的文档错误.顺便说一下,我正在 Heroku 上运行 Rails 3.1 和 Cedar stack.

I spent half a freakin' day on this and finally got mine working now. Quite frustrated as it was due to a poor documentation error. I'm running Rails 3.1 and Cedar stack on Heroku by the way.

所以 http://devcenter.heroku.com/articles/sendgrid 会告诉你将您的 SMTP 设置内容放在 config/initializers/mail.rb 中.但是...在 http://docs.sendgrid.com/documentation/get-started/integrate/examples/rails-example-using-smtp/ 它说把你所有的 SMTP 设置放在 config/environment.rb 而不是 config/initializers/mail.rb

So http://devcenter.heroku.com/articles/sendgrid will tell you to put your SMTP settings stuff in config/initializers/mail.rb. BUT... on http://docs.sendgrid.com/documentation/get-started/integrate/examples/rails-example-using-smtp/ it says to put all your SMTP settings stuff in config/environment.rb instead of config/initializers/mail.rb

因此,解决方案是将其放入您的 environment.rb 文件中.这是我的 environment.rb 的样子:

So the solution is to put that in your environment.rb file. This is how my environment.rb looks:

# Load the rails application
require File.expand_path('../application', __FILE__)

# Initialize the rails application
Freelanceful::Application.initialize!

# Configuration for using SendGrid on Heroku
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
  :user_name => "yourSendGridusernameyougetfromheroku",
  :password => "yourSendGridpasswordyougetfromheroku",
  :domain => "staging.freelanceful.com",
  :address => "smtp.sendgrid.net",
  :port => 587,
  :authentication => :plain,
  :enable_starttls_auto => true
}

要获取您的 SendGrid 用户名和密码,请输入

To get your SendGrid username and password, type

$ heroku config -long

希望能帮助......以及更多人在未来解决这个头痛问题.

Hope that helps.. and more people in the future of this headache.

这篇关于Ruby on Rails 中的 Sendgrid/电子邮件发送问题(托管在 Heroku 上)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆