问题
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?
回答1:
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.
回答2:
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']
}
来源:https://stackoverflow.com/questions/59514512/rails-5-2-netsmtpauthenticationerror-535-authentication-failed-account-disa