我无法使用我的Rails应用程序使用Gmail发送电子邮件。我可以在本地开发环境中发送电子邮件,但我无法从Heroku发送。 这是我的配置文件。
application.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日志中,我看到它说“#34;发送电子邮件到..."”,它使模板正常,没有任何错误,但我没有收到任何电子邮件。我也检查了Spam文件夹,但没有发送电子邮件。
production.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"
我错过了什么?
答案 0 :(得分:1)
这是一个我永远有效的应用程序,邮件仍然有效。尝试将auth类型更改为符号而不是字符串。所以:简单而不是'普通'。
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"