简体   繁体   English

Devise实际何时发送确认邮件?

[英]When does Devise actually send reconfirmation emails?

I'm trying to add email confirmation to a model called "Project" in a Rails app: users should be able to set an email address for a project, which is not saved until they click a confirmation link sent to the email address provided. 我正在尝试在Rails应用程序中将电子邮件确认添加到名为“项目”的模型中:用户应该能够为项目设置电子邮件地址,除非单击单击发送到所提供电子邮件地址的确认链接,否则该电子邮件地址不会保存。

Although I have no need for its authentication features, I thought the Devise gem might be useful. 尽管我不需要其身份验证功能,但我认为Devise gem可能有用。 I was hoping to use :reconfirmable to implement the feature: when the user tries to save an email to the project, it instead is saved to the unconfirmed_email column until they confirm. 我希望使用:reconfirmable来实现该功能:当用户尝试将电子邮件保存到项目时,它会保存到unconfirmed_email列中,直到他们确认为止。

It appears, partly, to be working -- the database is updated correctly, a token is generated, the "confirmation_sent_at" field is set. 看起来部分在起作用-正确更新数据库,生成令牌,设置“ confirmation_sent_at”字段。 But no email template is rendered (and no email is sent). 但是没有呈现电子邮件模板(也没有发送电子邮件)。 Looking at the code path in lib/devise/models.rb I can see how, before the email field is saved to, a method is called that intercepts that save and instead saves to unconfirmed_email. 查看lib / devise / models.rb中的代码路径,我可以看到在将电子邮件字段保存到之前如何调用一个方法,该方法拦截保存并改为保存到unconfirmed_email。 But where is the email send actually triggered? 但是实际在何处触发了发送电子邮件? What do I have to do to activate it? 我必须怎么做才能激活它?

Assuming that you have correctly configured Devise to use the :confirmable feature and configured your email properly ( as described in this answer) . 假设您已正确配置Devise以使用:confirmable功能并正确配置了电子邮件( 如本答案所述) Then it should be as simple as calling this: 然后,它应该像调用此命令一样简单:

user.send_confirmation_instructions # where user is one of your Devise users

At the very least, making the send_confirmation_instructions call should show that the email is sending in the Rails log. 至少,进行send_confirmation_instructions调用应该表明电子邮件正在Rails日志中发送。 If that is the case but you don't ever receive an email then you have your email configured incorrectly. 如果是这种情况,但是您从未收到电子邮件,则您的电子邮件配置不正确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM