Ruby on Rails:用户名/密码错误?(535 Auth失败)

Jef*_*key 4 ruby ruby-on-rails devise sendgrid

我刚刚在Bloc完成了我的红宝石基础课程,我开始把头埋进轨道开发中.事情进展顺利,直到我用设计和确认电子邮件打到这个障碍.我试着谷歌搜索并环顾其他一些问题,但实际上找不到任何给我任何东西,我可以拉出来并适用于我的情况.

我在注册帐户时收到以下错误.

Devise中的Net :: SMTPAuthenticationError :: RegistrationsController #create

535验证失败:用户名/密码错误


在#976行附近从源中提取错误

def check_auth_response(res)
  unless res.success?
    raise SMTPAuthenticationError, res.message
  end
end
Run Code Online (Sandbox Code Playgroud)

从其他帖子我知道你可能想看到我有一个如下所示的config/initializers/setup_mail.rb文件:

if Rails.env.development?
  ActionMailer::Base.delivery_method = :smtp
  ActionMailer::Base.smtp_settings = {
    address:        'smtp.sendgrid.net',
    port:           '587',
    authentication: :plain,
    user_name:      ENV['SENDGRID_USERNAME'],
    password:       ENV['SENDGRID_PASSWORD'],
    domain:         'heroku.com',
    enable_starttls_auto: true
  }
end
Run Code Online (Sandbox Code Playgroud)

这是一个application.yml文件示例:

SENDGRID_PASSWORD: 
SENDGRID_USERNAME:
SECRET_KEY_BASE:
Run Code Online (Sandbox Code Playgroud)

在任何人建议之前,我的config/environments/development.rb中还有以下内容:

config.action_mailer.default_url_options = { host: 'localhost:3000'}
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
# Override Action Mailer's 'silent errors' in development
config.action_mailer.raise_delivery_errors = true
Run Code Online (Sandbox Code Playgroud)

如果你想看到任何其他文件让我知道,我会将它们添加到这篇文章中.

小智 9

恭喜并欢迎黑客入侵世界.

您获得的错误意味着SendGrid服务器收到了错误的用户名+密码组合.

有可能您的环境变量为空,并且您application.yml的SendGrid用户名+密码未正确加载您的文件.

您可以通过在代码中的某个位置打印它们来确认这一点.在控制器工作.

puts "SENDGRID_USERNAME: #{ENV['SENDGRID_USERNAME']}"
puts "SENDGRID_PASSWORD: #{ENV['SENDGRID_PASSWORD']}"
Run Code Online (Sandbox Code Playgroud)

我怀疑他们是零.

我建议阅读https://quickleft.com/blog/simple-rails-app-configuration-settings/,了解如何将它们输入您的应用程序.

如果您需要更多帮助,请告诉我们!

  • 用户名和通行证不为零,它们显示为预期的芽 (2认同)
  • @eddiezane 最终通过删除 sendgrid 插件并取消设置 user/pass 变量然后重新添加插件来解决这个问题,但这次使用 `heroku addons:create sendgrid:starter` 而不是 `heroku addons:add sendgrid:starter` (2认同)

小智 6

自 2020 年第四季度起需要两因素身份验证,所有 Twilio SendGrid API 端点将拒绝通过基本身份验证使用用户名和密码进行的新 API 请求和 SMTP 配置。

我从过去几年一直运行的应用程序中收到了类似的问题。从现在开始,基本身份验证不起作用,您需要使用替代身份验证机制。Heroku sendgrid 安装时的自动配置尚未更新以反映这一点。

来源:https : //sendgrid.com/docs/for-developers/sending-email/upgrade-your-authentication-method-to-api-keys/