Rails 5.2 Net::SMTPAuthenticationError - 在发送电子邮件时(本地主机和Heroku)出现535身份验证失败的错误:帐户被禁用

10
我正在尝试使Rails 5.2的邮件发送器工作,但在localhost和我的Heroku production环境中都遇到了Net::SMTPAuthenticationError - 535 Authentication failed: account disabled错误。
邮件发送器的代码如下:
class AdminNotificationsMailer < ApplicationMailer
  default from: "liz@linchpinindustries.com"

  def new_rfp(rfp)
    @rfp = rfp
    mail(
      :to => "liz@linchpinindustries.com",
      :subject => 'New RFP Alert!'
    )
  end

  def new_contact_us(contact)
    @contact = contact
    mail(
      to: "liz@linchpinindustries.com",
      subject: 'New Contact Us Submission on LPI'
    )
  end

end

在我的rfp#create action中触发(对于第一个邮件,即new_rfp),代码如下:

def create
    @rfp = Rfp.new(rfp_params)

    respond_to do |format|
      if @rfp.save!
        AdminNotificationsMailer.new_rfp(@rfp).deliver
        format.html { redirect_to root_path, notice: "Thanks for your request!  We'll get back to you ASAP.  Stay tuned!" }
        format.json { render :show, status: :created, location: @rfp }
      else
        format.html { render :new }
        format.json { render json: @rfp.errors, status: :unprocessable_entity }
      end
    end
  end

我已经配置了Sendgrid,并使用puts进行了用户名和密码的双重检查(在本地主机和生产环境中都是正确的)。

我在我的environment.rb中有以下内容:

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

我已经查阅了像这个这个的帖子,但都没有起作用。

现在我被难住了。有谁能看出这个错误发生的原因吗?

3个回答

8
您的设置看起来都正确,那么这是否只是一件简单的事情呢?
Net::SMTPAuthenticationError - 535 Authentication failed: account disabled

您的帐户因某种原因被禁用。请与Sendgrid联系,确保您的帐户正常运行。


1
由于某种原因,我不得不删除并重新配置插件...但是一开始我无法重新添加它,因为我的账户已被标记为红旗。我联系了支持团队,他们说这显然是一个“误报”情况,道歉并重新激活了我的账户。如此奇怪,但现在它可以使用了! - Liz
这是正确的,@Liz大部分时间当一个账户长时间没有活动时,系统会对其进行标记。 - v2lrf

5

我曾遇到类似的错误信息,原因是我在sendgrid上启用了两步验证(2FA),但当时没有意识到我需要在应用程序中更新配置信息。

现在,你不再提供自定义的用户名和密码,而需要提供 username = "apikey" 和 API密钥作为密码。

ActionMailer::Base.smtp_settings = {
  domain: 'YOUR_DOMAIN.COM',
  address:        "smtp.sendgrid.net",
  port:            587,
  authentication: :plain,
  user_name:      'apikey',
  password:       ENV['SENDGRID_API_KEY']
}

这篇文章帮助我找到了解决方案。


0

你能测试一下这个配置吗?在我的项目中它是正常工作的。

ActionMailer::Base.smtp_settings = {
    :address => "smtp.sendgrid.net",
    :port => 465,
    :domain => "vibol.xyz",
    :ssl => true,
    :enable_starttls_auto => true,
    :authentication => :login,
    :user_name => ENV['SENDGRID_USERNAME'],
    :password => ENV['SENDGRID_PASSWORD']
  }

我记得我曾经遇到过一些问题(但无法回忆细节),在花费了很多时间测试后,通过使用上述配置,我最终解决了这个问题。 - Vibol
我尝试了这个,一切都顺利通过了,没有错误,服务器显示电子邮件已发送,但是电子邮件仍然没有到达!(是的,我检查了垃圾邮件。) - Liz
它在我的 rfp#create 方法中:AdminNotificationsMailer.new_rfp(@rfp).deliver - Liz

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接