【问题标题】:Can't send email using Gmail on Heroku无法在 Heroku 上使用 Gmail 发送电子邮件
【发布时间】:2018-05-08 13:13:40
【问题描述】:

我的 Rails 应用无法使用 Gmail 发送电子邮件。我可以在本地开发环境中发送电子邮件,但不能从 Heroku 发送。 这是我的配置文件。

应用程序.rb

  config.action_mailer.smtp_settings = {
    :address        => 'smtp.gmail.com',
    :domain         => 'gmail',
    :port           => 587,
    :user_name        => ENV['GMAIL_USERNAME'],
    :password         => ENV['GMAIL_PASSWORD'],
    :authentication     => 'login',
    :enable_starttls_auto => true
  }

我已经尝试过身份验证:'login' 和 'plain',但这也不起作用。我曾尝试将此配置都放入 application.rb 和 production.rb ,但没有奏效。我试过 domain: "my_my_name_on_heroku.com" 但这也没有用。我也尝试过'mail.google.com',但也没有运气。 我已经在 Heroku 上使用用户名和密码正确设置了环境变量(100% 确定)。 我启用了不太安全的应用程序以使应用程序在https://myaccount.google.com/lesssecureapps 上运行。没有两因素身份验证。我已启用验证码以允许通过 http://www.google.com/accounts/DisplayUnlockCaptcha 从不同设备登录,但仍然没有发送电子邮件。

在 Heroku 日志中,我看到它显示“正在向...发送电子邮件”,它使模板正常,没有任何错误,但我没有收到任何电子邮件。我也检查了垃圾邮件文件夹,但那里没有电子邮件。

生产.rb

  config.action_mailer.default_url_options = { host: 'my_app.herokuapp.com' }
  config.action_mailer.perform_caching = false
  config.action_mailer.perform_deliveries = true
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.raise_delivery_errors = false
  config.action_mailer.default :charset => "utf-8"

我错过了什么?

【问题讨论】:

  • 我会考虑使用 mailgun 而不是设置 gmail 的麻烦。

标签: ruby-on-rails email heroku


【解决方案1】:

这是一个我一直拥有的活跃应用程序,邮件仍然有效。尝试将身份验证类型更改为符号而不是字符串。所以 :plain 而不是 'plain'。

  config.action_mailer.smtp_settings = {
    :enable_starttls_auto => true,
    :address => 'smtp.gmail.com',
    :port => 587,
    :authentication => :plain,
    :domain => 'blarg.com',
    :user_name => 'info@blarge.com',
    :password => 'password'
  }

 config.action_mailer.default_url_options = { :host => 'blarg.heroku.com' }
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.default :charset => "utf-8"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-19
    • 2016-07-14
    • 2017-01-16
    • 1970-01-01
    • 2013-01-08
    • 1970-01-01
    • 2018-08-12
    相关资源
    最近更新 更多