Rails Mailer中的“Default From”错误导致Heroku上使用SendGrid发生SMTP错误

时间:2013-06-01 11:01:35

标签: ruby-on-rails email heroku ruby-on-rails-3.2 sendgrid

我正在使用Heroku和SendGrid设置Mail,并尝试使用Rails发送电子邮件时遇到以下错误:

Net::SMTPFatalError (550 Cannot receive from specified address <my-email@domain.com>: Unauthenticated senders not allowed
2013-06-01T10:52:34.767516+00:00 app[web.1]:   app/controllers/api/v1/post_controller.rb:84:in `reply'

此域名“my-email@domain.com”来自我的邮件程序中的“默认来自”字段:

class NotificationMailer < ActionMailer::Base
  default from: "my-email@domain.com"

  def post_notification_email(params)
    # Send mail here
  end
end

我的大问题是我不知道到底要填写什么。这应该是我的电子邮件地址吗?它必须是我的域名吗?这是我的Heroku电子邮件吗?我的SendGrid电子邮件?不知道如何使SendGrid感到高兴。删除此行并希望填充某些内容也会导致错误。我被卡住了。其他人使用的是什么“默认来自”?

还有一件,如果它很重要:这仍然在开发中,所以我没有将它连接到域。我还没有真正创建一个SendGrid帐户,只是在Heroku上添加了我的应用程序的SendGrid插件。

更新:发布生产的动作邮件程序配置:

ActionMailer::Base.smtp_settings = {
    :address        => 'smtp.sendgrid.net',
    :port           => '25',
    :authentication => :plain,
    :user_name      => ENV['SENDGRID_USERNAME'],
    :password       => ENV['SENDGRID_PASSWORD'],
    :domain         => 'domain.com',
    :enable_starttls_auto => true
  }

1 个答案:

答案 0 :(得分:0)

验证您的action_mailer配置正确,( config / production.rb ):

  # Sendgrid
  config.action_mailer.smtp_settings = {
    address: "smtp.sendgrid.net",
    port: 25,
    domain: "example.com",
    authentication: "plain",
    user_name: ENV["SENDGRID_USERNAME"],
    password: ENV["SENDGRID_PASSWORD"]
  }

不要忘记更改参数! 将sendgrid添加到您的heroku应用程序中,如下所示(在您的终端中):

heroku addons:add sendgrid:starter

提交更改并将您的应用程序部署到heroku。您应该能够从之前定义的域发送电子邮件。