Ruby Rails:如何配置 Devise Mailer?
Ruby on Rails: How to Configure the Devise Mailer?
我已经在 Rails 的 Ruby 上提交了申请。我正在使用 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"
}
当我测试它时,它看起来不错,它不会在应用程序上抛出任何异常,但电子邮件永远不会到来。请问,我该如何配置?
对于本地使用,我建议使用 letter_opener。
对于部署应用程序,我建议使用像 Sendgrid 这样的服务,它有一个免费套餐,足以满足小型应用程序的需求。
如果您坚持为 e-mails 使用 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
}
偶然发现了这个较旧的问题,我想我会在这里提供一个最新的答案。如果您出于任何原因(原型设计、开发等 - 无判断)尝试将 Gmail 帐户与您的 Devise Rails 应用程序一起使用,Pedro 的回答很准确,但有 1 个例外。 SMTP 服务器的密码不是您的用户密码。这在过去可能没问题,但现在您必须生成一个与用户密码分开的新应用密码。
可在 Google 的支持网站上找到相关说明:https://support.google.com/accounts/answer/185833?hl=en
我已经在 Rails 的 Ruby 上提交了申请。我正在使用 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"
}
当我测试它时,它看起来不错,它不会在应用程序上抛出任何异常,但电子邮件永远不会到来。请问,我该如何配置?
对于本地使用,我建议使用 letter_opener。
对于部署应用程序,我建议使用像 Sendgrid 这样的服务,它有一个免费套餐,足以满足小型应用程序的需求。
如果您坚持为 e-mails 使用 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
}
偶然发现了这个较旧的问题,我想我会在这里提供一个最新的答案。如果您出于任何原因(原型设计、开发等 - 无判断)尝试将 Gmail 帐户与您的 Devise Rails 应用程序一起使用,Pedro 的回答很准确,但有 1 个例外。 SMTP 服务器的密码不是您的用户密码。这在过去可能没问题,但现在您必须生成一个与用户密码分开的新应用密码。
可在 Google 的支持网站上找到相关说明:https://support.google.com/accounts/answer/185833?hl=en