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

Rin*_*cke 16 ruby-on-rails actionmailer heroku sendgrid

我有一个问题,让sendgrid成功地在rails 3.1应用程序上发送电子邮件,该应用程序使用authlogic进行身份验证并部署在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的经验的人知道发生了什么事吗?

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

Jam*_*s F 44

我花了半个时间在这上面,终于让我的工作了.相当沮丧,因为它是由于文档错误导致的.顺便说一下,我正在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
}
Run Code Online (Sandbox Code Playgroud)

要获取SendGrid用户名和密码,请键入

$ heroku config -long
Run Code Online (Sandbox Code Playgroud)

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