我在Ruby on Rails上创建了一个应用程序。我正在使用Devise,我需要使用可恢复的密码功能。 我在development.rb上找到了这些配置:
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default :charset => "utf-8"
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 2525,
domain: "gmail.com",
authentication: "plain",
enable_starttls_auto: true,
user_name: "MY_EMAIL",
password: "MY_PASS"
}
当我测试它时,它看起来没问题,它不会在应用程序上抛出任何异常,但电子邮件永远不会出现。请问,我该如何配置?
答案 0 :(得分:3)
在本地使用时,我建议使用类似letter_opener的内容。
对于部署应用程序,我建议使用像Sendgrid这样的服务,它有一个足够小的应用程序的免费套餐。
如果您坚持使用GMail收发电子邮件,请尝试使用TLS:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
domain: "gmail.com",
port: 587,
user_name: "jorge@example.org",
password: "your_password",
authentication: 'plain',
enable_starttls_auto: true
}
答案 1 :(得分:0)
偶然发现了这个较旧的问题,并认为我会在这里提供当前的答案。如果您出于任何原因(原型设计、开发等 - 无判断)尝试在您的 Devise Rails 应用程序中使用 Gmail 帐户,Pedro 的答案是正确的,只有 1 个例外。 SMTP 服务器的密码不是您的用户密码。这在过去可能没问题,但现在您必须生成一个与用户密码分开的新应用密码。
可在此处的 Google 支持网站上找到路线:https://support.google.com/accounts/answer/185833?hl=en