【问题标题】:Wrong "Default From" value in Rails Mailer leads to SMTP error on Heroku with SendGridRails Mailer 中错误的“Default From”值会导致 Heroku 上的 SendGrid 出现 SMTP 错误
【发布时间】:2013-05-28 03:23:39
【问题描述】:

我正在使用 Heroku 和 SendGrid 设置邮件,并在尝试使用 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”来自我的 Mailer 中的“默认发件人”字段:

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

  def post_notification_email(params)
    # Send mail here
  end
end

我最大的问题是我不知道究竟要在这里填写什么。这应该是我的电子邮件地址吗?它必须是我的域吗?是我的 Heroku 电子邮件吗?我的 SendGrid 电子邮件?不知道该怎么做才能让 SendGrid 开心。删除这条线并希望可以填写一些有效的东西也会导致错误。我被困住了。其他人的“默认来源”是什么?

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

更新:发布我的生产操作邮件配置:

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
  }

【问题讨论】:

  • 发件人地址没有问题。该错误消息意味着 SendGrid 拒绝您的凭据或身份验证方法。您可以发布您的 ActionMailer 配置以用于生产吗?
  • 刚刚将我的邮件配置发布到问题中。我仍然对这一切感到困惑,我不确定问题出在哪里。以上对我来说似乎不错,并且凭据似乎是自动填写的。
  • 如果您运行heroku config,您会在该列表中看到您的 SendGrid 用户名和密码吗?我的猜测是您的凭据配置不正确。

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


【解决方案1】:

验证您的 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"]
  }

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

heroku addons:add sendgrid:starter

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

【讨论】:

  • 我已经添加了 SendGrid,它已经全部部署到 Heroku。我之前没有更改“域”参数,虽然 Duh,就是这样,但我仍然遇到同样的问题。我应该在这里填写哪个域?我自己网站的域名?还是“*.herokuapp.com”?或者它是什么?
  • 定义你的heroku域:“your-app.herokuapp.com”
  • 对不起@dpaluy,我才意识到我从来没有回复过这个。我按照文档和您所描述的内容重新开始,瞧,我让它工作了。坏消息是我仍然不确定实际问题是什么。但是非常感谢您为我指明了检查和注意事项的正确方向!
猜你喜欢
  • 2014-05-30
  • 1970-01-01
  • 2013-12-27
  • 2018-05-17
  • 2016-08-18
  • 1970-01-01
  • 1970-01-01
  • 2022-10-20
  • 2012-07-10
相关资源
最近更新 更多