16

我无法让 sendgrid 在使用 authlogic 进行身份验证并部署在 heroku 上的 rails 3.1 应用程序上成功发送电子邮件。我在 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 的经验的人知道发生了什么?

太感谢了。你们是最棒的!!!

4

3 回答 3

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
}

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

$ heroku config -long

希望对您有所帮助.. 和更多的人在这个头痛的未来。

于 2012-01-10T08:54:32.557 回答
0

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

也就是说,使用 SendGrid 插件时,您无需在生产环境中配置邮件,因为它会在您部署应用程序时自动为您配置。

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

于 2012-01-08T23:24:20.783 回答
0

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

但是,在将应用程序激活到 Heroku 后,您确实需要至少执行一次 git push 来设置这些设置。我今天早上犯了那个错误,找到了你的帖子。

于 2013-07-15T23:51:55.713 回答