Warm tip: This article is reproduced from serverfault.com, please click

Rails 5.2 Net::SMTPAuthenticationError

发布于 2019-12-28 20:13:27

I'm trying to get a Rails 5.2 mailer working, but am coming across a Net::SMTPAuthenticationError - 535 Authentication failed: account disabled error on both localhost and my Heroku production environment.

The mailer looks like this:

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

With the trigger in my rfp#create action (for the first mailer, the new_rfp one):

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

I have provisioned Sendgrid and double checked my username and password with puts (it is correct on localhost and production).

I have the following in my 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
}

I've consulted posts like this and this, but nothing is working.

I'm officially stumped. Can anyone see why this error is occurring?

Questioner
Liz
Viewed
0
Ben Trewern 2020-01-02 10:02:45

Everything in your settings looks correct so is this not just as simple as

Net::SMTPAuthenticationError - 535 Authentication failed: account disabled

your account is for whatever reason disabled. Check with Sendgrid that your account is up and running correctly.