Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 5.2 Net::SMTPAuthenticationError - 535 Authentication failed: account disabled When Sending Email (Localhost and Heroku)

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: "[email protected]"

  def new_rfp(rfp)
    @rfp = rfp
    mail(
      :to => "[email protected]",
      :subject => 'New RFP Alert!'
    )
  end

  def new_contact_us(contact)
    @contact = contact
    mail(
      to: "[email protected]",
      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?

like image 650
Liz Avatar asked Dec 28 '19 20:12

Liz


2 Answers

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.

like image 106
Ben Trewern Avatar answered Oct 19 '22 15:10

Ben Trewern


I was getting a similar error message, and the problem was that I turned on 2FA authentication on my sendgrid, and didn't realize I had to update my configuration in the app when I did that.

Now, instead of a custom username and password, you have to provide username = "apikey" and password is your api key

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.

like image 22
gwalshington Avatar answered Oct 19 '22 16:10

gwalshington