【问题标题】:Ruby on Rails: bad username / password? (535 Auth failed)Ruby on Rails:用户名/密码错误? (535 验证失败)
【发布时间】:2015-05-13 22:20:55
【问题描述】:

我刚刚在 Bloc 完成了我的 ruby​​ 基础课程,我开始埋头研究 Rails 开发。事情进展顺利,直到我用设计和确认电子邮件遇到了这个障碍。我尝试使用谷歌搜索并查看其他一些问题,但实际上找不到任何可以让我从中汲取并适用于我的情况的任何问题。

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

Net::SMTPAuthenticationError in Devise::RegistrationsController#create

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


从第 #976 行附近的源代码中提取的错误

def check_auth_response(res)
  unless res.success?
    raise SMTPAuthenticationError, res.message
  end
end

从其他帖子中,我知道您可能希望看到我有一个如下所示的 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

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

SENDGRID_PASSWORD: 
SENDGRID_USERNAME:
SECRET_KEY_BASE:

在有人建议之前,我的 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

如果您想查看任何其他文件,请告诉我,我会将它们添加到此帖子中。

【问题讨论】:

    标签: ruby-on-rails ruby devise sendgrid


    【解决方案1】:

    恭喜并欢迎来到黑客世界。

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

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

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

    puts "SENDGRID_USERNAME: #{ENV['SENDGRID_USERNAME']}"
    puts "SENDGRID_PASSWORD: #{ENV['SENDGRID_PASSWORD']}"
    

    我怀疑它们是 nil。

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

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

    【讨论】:

    • 很好的答案感谢@eddie。我开始将这些设置中的一些设置为secrets.yml 文件中的注释行,然后使用export 在shell 中手动设置。有任何理由拥有secrets.yml 文件还是应该将所有这些合并到application.yml 中?
    • 用户名和密码不为零,它们显示为预期的芽
    • Here's 一个最小的工作示例。如果你把它扔到 GitHub 上,很高兴看看你有什么。
    • @eddiezane 最终解决了这个问题,方法是删除 sendgrid 插件并取消设置用户/密码变量,然后重新添加插件,但这次使用 heroku addons:create sendgrid:starter 而不是 heroku addons:add sendgrid:starter
    • @JeffWilkey 我只是听从了你的建议,马上就看到An error was encountered when contacting the add-on partner to create sendgrid:starter: Error Provisioning User - User status - banned。对于上下文,这是我第一次使用 sendgrid 和 sendgrid + heroku 组合。两者都不是很好的用户体验。
    【解决方案2】:

    从 2020 年第四季度开始需要双重身份验证,所有 Twilio SendGrid API 端点将拒绝新的 API 请求和 SMTP 通过 Basic 使用用户名和密码进行的配置 身份验证。

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

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

    【讨论】:

      【解决方案3】:

      在我的情况下,错误是使用我的 apikey 的 id 作为用户名,但这是错误的,正确的值 user_name 是“apikey”,(字面意思是“apikey”字符串),正如他们在集成示例中所说, https://sendgrid.com/docs/for-developers/sending-email/rubyonrails/ https://app.sendgrid.com/guide/integrate/langs/smtp

      ActionMailer::Base.smtp_settings = {
      :user_name => 'apikey', # This is the string literal 'apikey', NOT the ID of your API key
      :password => '<SENDGRID_API_KEY>', # This is the secret sendgrid API key which was issued during API key creation
      :domain => 'yourdomain.com',
      :address => 'smtp.sendgrid.net',
      :port => 587,
      :authentication => :plain,
      :enable_starttls_auto => true
      }
      

      【讨论】:

      • 天哪。我也一样!!!
      猜你喜欢
      • 2021-09-23
      • 2015-04-12
      • 2017-11-29
      • 2018-10-24
      • 2011-07-04
      • 2019-11-18
      • 1970-01-01
      • 1970-01-01
      • 2016-08-30
      相关资源
      最近更新 更多