【问题标题】:Sending emails through Gmail on Rails app + Heroku通过 Gmail on Rails 应用程序 + Heroku 发送电子邮件
【发布时间】:2017-10-06 11:55:11
【问题描述】:

我开设了一个 Google Apps 帐户并注册了电子邮件。我正在尝试使用 sidekiq 将它连接到我在 Heroku 上运行的 Rials 应用程序。 Letter opener 在开发方面运行良好,因此设置很好,但使用 Google 发送电子邮件不起作用。

这是 config/initializers/mailer.rb

ActionMailer::Base.helper "application"
ActionMailer::Base.smtp_settings = {   
  address:              'smtp.gmail.com',
  port:                 587,
  domain:               domain.com,
  user_name:            name@domain.com,
  password:             gmailpassword,
  authentication:       'plain',
  # authentication:       'login',
  tls:                  true,
  enable_starttls_auto: true
}

生产.rb

config.action_mailer.default_url_options = { host: 'domainname.com' }
ActionMailer::Base.delivery_method = :smtp

在 Google 我关闭了两步验证,我打开了不太安全的应用程序等,但它无法正常工作。要么它显示验证错误。在更改设置等期间,我遇到了三个错误:

  1. SMTPAuthenticationError

  2. 未捕获的异常:534-5.7.14

  3. OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=unknown state: unknown protocol

知道如何修复它并正确设置 gmail 吗?谢谢

【问题讨论】:

    标签: ruby-on-rails email heroku


    【解决方案1】:

    除了what was said here,您还需要在登录您尝试发送的gmail 帐户时转到http://www.google.com/accounts/DisplayUnlockCaptcha。我可以确认今天在 Heroku 上这对我有用。

    【讨论】:

    • 小心,因为这可能不会持续太久!一周后,我得到它不再工作了。 :(
    【解决方案2】:

    config/application.rb 中的 Smtp 设置

      config.action_mailer.delivery_method = :smtp
      config.action_mailer.smtp_settings = {
          :address => "smtp.gmail.com",
          :port => 587,
          :domain => "gmail.com",
          :user_name => "xxxxx@gmail.com",
          :password => "xxxxxx",
          :authentication => "plain",
          :enable_starttls_auto => true
      }
    

    访问您的 gmail 设置并启用安全性较低的应用以使应用正常运行。链接:google.com/settings/security/lesssecureapps

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-15
      • 2015-07-31
      • 1970-01-01
      • 2013-06-09
      • 2012-01-07
      • 2023-03-19
      相关资源
      最近更新 更多