我无法让我的 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
}
我尝试过身份验证:“登录”和“普通”,但这也不起作用。我尝试将此配置放入 application.rb 和 production.rb 中,但这不起作用。我尝试过域名:“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"
我缺少什么?
这是我一直使用的一个活跃的应用程序,邮件仍然有效。尝试将身份验证类型更改为符号而不是字符串。所以:plain 而不是“plain”。
config.action_mailer.smtp_settings = {
:enable_starttls_auto => true,
:address => 'smtp.gmail.com',
:port => 587,
:authentication => :plain,
:domain => 'blarg.com',
:user_name => '[email protected]',
: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"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)