【问题标题】:535-5.7.8 Username and Password not accepted in Rails Mailer using Gmail535-5.7.8 在使用 Gmail 的 Rails Mailer 中不接受用户名和密码
【发布时间】:2020-12-16 08:51:20
【问题描述】:

我正在使用 Rails Mailer 和 Gmail 发送电子邮件。但我不断收到Net::SMTPAuthenticationError 535-5.7.8 Username and Password not accepted 错误。

我查看了有关此问题的其他问题,但不幸的是,它们没有帮助。

我启用了两步验证,并且我确实为我的 Rails 应用程序创建了应用程序密码。

这是我在production.rb中的配置:

  config.action_mailer.perform_caching = false

  config.action_mailer.delivery_method = :smtp
  host = 'myhost'
  config.action_mailer.default_url_options = { host: host }

  config.action_mailer.smtp_settings = {
    address: 'smtp.gmail.com',
    domain: 'myhost',
    port: 587,
    user_name: 'myemail@domain.com',
    password: ENV['GMAIL_APP_PASSWORD'],
    authentication: 'plain',
    enable_starttls_auto: true
  }

现在,值得注意的是,我使用的是非 Gmail 地址,但我使用的是 GSuite,它允许我使用该地址登录 Gmail,并将其用作 Gmail 地址。

如果这意味着什么,在尝试使用 Rails 发送电子邮件后,我确实收到了一封关于阻止登录警报的电子邮件。再次注意,我使用的是应用密码,而不是帐户的通用密码。

看到一些答案说我必须启用不太安全的应用程序选项,但是当两步处于活动状态时我无法启用它。

【问题讨论】:

    标签: ruby-on-rails smtp gmail actionmailer


    【解决方案1】:

    不太安全的应用

    您是否允许使用不太安全的应用程序?请这样做,看看是否有帮助。 Less secure apps

    清除验证码

    Display Unlock Captcha

    2fa 使用应用密码。

    如果在 Gmail 中使用两步验证,您可能需要应用程序密码。 Create & use App Passwords

    Xoauth2

    如果还是不行,你可能需要考虑检查xoauth2-protocol

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-29
      • 2016-05-22
      • 2021-08-05
      • 2023-03-22
      • 2022-08-12
      相关资源
      最近更新 更多