问题
We are using Sendgrid for sending SMTP emails in our Rails 5 app, I had a weird error stating:
451 Authentication failed: Could not authenticate
My configuration in production.rb
file is like this:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
user_name: ENV['ENV_username'],
password: ENV['ENV_PASSWORD'],
domain: 'xxxxxx',
address: 'smtp.sendgrid.net',
port: 587,
authentication: :plain,
enable_starttls_auto: true
}
The exception that we have is as follows:
vendor/ruby-2.6.3/lib/ruby/2.6.0/net/smtp.rb:981 check_auth_response
vendor/ruby-2.6.3/lib/ruby/2.6.0/net/smtp.rb:736 auth_plain
vendor/ruby-2.6.3/lib/ruby/2.6.0/net/smtp.rb:728 authenticate
vendor/ruby-2.6.3/lib/ruby/2.6.0/net/smtp.rb:565 do_start
vendor/ruby-2.6.3/lib/ruby/2.6.0/net/smtp.rb:518 start
vendor/ruby-2.6.3/lib/ruby/2.6.0/monitor.rb:230 mon_synchronize
vendor/ruby-2.6.3/lib/ruby/2.6.0/monitor.rb:230 mon_synchronize
app/controllers/xxxxxx/registrations_controller.rb:3 create
Generally, the emails are sent correctly & everything is working fine but for this issue, it is a bit vague what the problem is, from Sendgrip docs I can see it means
451
Temporary local problem - please try later
The message simply failed, usually due to a far-end server error. We continue to retry messages for up to 72 hours.
I am not sure if that means an exception from Sendgrid side or on my application
Any thoughts about this?
来源:https://stackoverflow.com/questions/58418195/rails-5-smtp-sendgrid-451-authentication-failed-could-not-authenticate