【发布时间】: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