Ruby on Rails中的Sendgrid /电子邮件发送问题(在Heroku上托管)

我有一个问题,让sendgrid成功地在rails 3.1应用程序上发送电子邮件,该应用程序使用authlogic进行身份validation并部署在heroku上。 我在config / environments / [development.rb和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,上面的代码是相同的除外

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

当我运行它的开发模式时,我收到以下错误报告:

 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的经验的人知道发生了什么事吗?

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

我花了半个半天的时间,终于让我的工作了。 相当沮丧,因为它是由于文档错误导致的。 顺便说一下,我正在Heroku上运行Rails 3.1和Cedar堆栈。

因此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 而不是配置/初始化/ mail.rb

所以解决方案是将它放在environment.rb文件中。 这就是我的environment.rb的样子:

 # 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用户名和密码,请键入

 $ heroku config -long 

希望有助于..和更多人在未来的这个头痛。

我假设你的意思是在本地开发模式? 如果是这样,我认为SendGrid插件不允许您从Heroku网络外部发送电子邮件(因为他们有他们希望您使用的独立帐户)。

这样说,在使用SendGrid插件时,您不需要在生产中配置邮件,因为在部署应用程序时会自动为您配置。

因此,您可以删除config.action_mailer.smtp_settings代码,并在开发中使用默认值。

另请注意,如果您在Bamboo堆栈上运行Heroku应用程序,则无需在environment.rb文件中配置您的设置,因为Heroku会为您执行此操作。

但是,在将应用程序激活到Heroku以设置这些设置后,您需要至少进行一次git push。 我今天早上弄错了,找到了你的post。