【发布时间】: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