10

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?

Liz
  • 1,369
  • 2
  • 26
  • 61

3 Answers3

8

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.

Ben Trewern
  • 1,583
  • 1
  • 10
  • 13
  • 1
    For some reason I had to delete and reprovision the addon...but I wasn't allowed to re-add it at first because my account had been red flagged. I contacted support and they said it was clearly a "false positive" situation, apologized, and reactivated my account. So bizarre, but it works now! – Liz Jan 08 '20 at 19:04
  • This is correct, @Liz most of the time when an account is sleeping for a while, the red flag it. – v2lrf Apr 03 '20 at 22:10
5

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.

gwalshington
  • 1,418
  • 2
  • 30
  • 60
0

Can you test this configuration? It's working on my project.

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
  • 1,158
  • 1
  • 9
  • 23
  • I remember I had some issue (but cannot remember detail), and after spending lots of time testing I get it working by using above configuration. – Vibol Jan 02 '20 at 12:00
  • I tried this and everything went through, it had no errors, the server showed the email was sent, but the email still never arrived! (Yes, I checked spam.) – Liz Jan 04 '20 at 04:37
  • It's in my `rfp#create` method: `AdminNotificationsMailer.new_rfp(@rfp).deliver`. – Liz Jan 05 '20 at 22:32