简体   繁体   中英

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.

Although I have no need for its authentication features, I thought the Devise gem might be useful. 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.

It appears, partly, to be working -- the database is updated correctly, a token is generated, the "confirmation_sent_at" field is set. 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. 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) . 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. If that is the case but you don't ever receive an email then you have your email configured incorrectly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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