无法在Heroku上使用Gmail发送电子邮件 [英] Can't send email using Gmail on Heroku
问题描述
我无法使用Rails应用程序通过Gmail发送电子邮件。我可以在本地开发环境中发送电子邮件,但不能从Heroku发送电子邮件。
这是我的配置文件。
I can't get my Rails app to send emails using Gmail. I can send emails on my local development environment but I can't send it from Heroku. This is my config file.
application.rb
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 。没有2要素身份验证。我已启用验证码,以允许通过 http://www.google.com/accounts/从不同设备登录。 DisplayUnlockCaptcha ,仍然没有电子邮件发送。
I have tried authentication: 'login' and 'plain' but that didn't work either. I have tried putting this config both into application.rb and production.rb and that didn't work. I've tried domain: "my_my_name_on_heroku.com" but that didn't work either. I have also tried 'mail.google.com' but no luck either. I have setup environment variables on Heroku with username and password properly (100% sure). I have enabled less secure apps to get the application working at https://myaccount.google.com/lesssecureapps. No 2-factor authentication. I have enabled captcha to allow to login from different devices at http://www.google.com/accounts/DisplayUnlockCaptcha and still no emails are sent.
在Heroku日志上,我看到它说正在发送电子邮件到...,它使模板很好,没有任何错误,但我没有收到任何电子邮件。我也检查了垃圾邮件文件夹,但那里没有电子邮件。
On Heroku logs I see that it says "Sending email to...", it renders the template fine, no errors whatsoever but I don't receive any emails. I've checked Spam folder as well but no emails there.
production.rb
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"
我缺少什么?
推荐答案
这是我永远拥有的活动应用程序,在该应用程序中邮件仍然有效。尝试将身份验证类型更改为符号而不是字符串。因此,:plain而不是 plain。
This is an active app I have had forever where the mail still works. Try changing the auth type to a symbol rather than a string. So :plain instead of '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"
这篇关于无法在Heroku上使用Gmail发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!