【问题标题】:Rails 5.2 Net::SMTPAuthenticationError - 535 Authentication failed: account disabled When Sending Email (Localhost and Heroku)Rails 5.2 Net::SMTPAuthenticationError - 535 身份验证失败:发送电子邮件时禁用帐户(本地主机和 Heroku)
【发布时间】:2019-12-28 20:13:27
【问题描述】:

我正在尝试让 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
}

我查阅过thisthis 之类的帖子,但没有任何效果。

我被正式难住了。谁能看到为什么会发生这个错误?

【问题讨论】:

    标签: ruby-on-rails sendgrid


    【解决方案1】:

    您的设置中的所有内容看起来都正确,所以这不只是像

    那么简单
    Net::SMTPAuthenticationError - 535 Authentication failed: account disabled
    

    无论出于何种原因,您的帐户都是disabled。请与 Sendgrid 确认您的帐户已启动并正常运行。

    【讨论】:

    • 出于某种原因,我不得不删除并重新配置插件...但一开始我不允许重新添加它,因为我的帐户已被标记为红色。我联系了支持人员,他们说这显然是“误报”情况,道歉并重新激活了我的帐户。太奇怪了,但现在可以了!
    • 这是正确的,@Liz 大部分时间当一个帐户在休眠一段时间时,红旗它。
    【解决方案2】:

    我收到了类似的错误消息,问题是我在我的 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']
    }
    

    This post helped me find the solution.

    【讨论】:

      【解决方案3】:

      你能测试一下这个配置吗?它正在处理我的项目。

      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']
        }
      

      【讨论】:

      • 我记得我遇到了一些问题(但不记得细节),经过大量时间测试后,我使用上述配置使其正常工作。
      • 我试过了,一切顺利,没有错误,服务器显示邮件已发送,但邮件仍未到达! (是的,我检查了垃圾邮件。)
      • 在我的rfp#create方法中:AdminNotificationsMailer.new_rfp(@rfp).deliver
      猜你喜欢
      • 2018-02-08
      • 2014-11-02
      • 1970-01-01
      • 2021-07-30
      • 2013-11-30
      • 2015-04-12
      • 2012-09-21
      • 2015-10-15
      • 2014-12-31
      相关资源
      最近更新 更多