ruby-on-rails - 如何设置来自 gmail 的密码重置电子邮件并获得许可?
问题描述
我正在尝试创建一个清除密码重置电子邮件以从我创建的 gmail 帐户发送。当有人点击“重置密码”时,我需要做什么才能完成此操作并发送密码重置电子邮件?我已经设置
config.mailer_sender = 'newemail@email.com'
对不起,如果这是一个愚蠢的问题,我对轨道和间隙还是新手。
解决方案
这是您在 Clearance 中配置要从其发送的特定电子邮件地址的方式。把它放在:config/initializers/clearance.rb
Clearance.configure do |config|
config.mailer_sender = "reply@example.com"
end
但在 Rails 中,您还需要配置服务器以发送电子邮件。/config/environments/development.rb
# Gmail configuration
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'example.com',
user_name: ENV['EMAIL_USER'],
password: ENV['EMAIL_PASS'],
authentication: 'plain',
enable_starttls_auto: true
}
但是,请密切注意两件事:
- 此示例使用 ENV 变量
EMAIL_USER
,EMAIL_PASS
它们是您的 bash 会话中需要存在的自定义环境变量(例如。$ export EMAIL_USER=my_email@gmail.com
) - 此示例假设您仅在开发中执行此操作(对于从个人 Gmail 帐户发送应该是正确的)。如果你想在生产中使用它,你应该在
/config/environments/production.rb
推荐阅读
- php - 合并json文件,覆盖
- java - Spring Boot Actuator 不读取 git.properties
- sql-server - 同一列的 Where 子句中的多个条件
- amazon-web-services - coredns 容器在尝试创建集群时卡在 containercreating 状态
- java - 在 REST POST 调用期间未从 Inherited 对象获取所有属性
- javascript - 如何在另一个表中创建一个 Bootstrap 响应表?
- debezium - 如何在 debezium 中将 offset.commit.policy 设置为 AlwaysCommitOffsetPolicy?
- sql - Oracle 等效于 SQL Server 中使用的 suser_name()
- python - 不能使用先知进行预测(Dataframe 的非 NaN 行少于 2 个)
- parameters - Solidity:函数参数的大小如何影响 gas 成本?