How to confirm email addrees in spring MVC web application

前端 未结 2 861
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-06 13:46

I am registering user with email address . but i want to send the user a confirmation link where if they click then their email address gets confirmed

I am using         


        
相关标签:
2条回答
  • 2021-02-06 14:38

    Among other tools you can use "java mail" package to send emails direclty from your application. Here's the link to API docs Java Mail API

    So the scenario could be like the following:

    • User account is created. It's in unconfirmed state now;
    • You generate a unique confirmation ID to your applicaiton. The easiest way is to use java.util.UUID.randomUUID().toString(). UUID is a random globally unique value.;
    • You store the ID (e.g. 0123)+account to the database for future use;
    • Send the URL+ID (http://yourapp.com/confirm?id=0123) as an email using javamail to the user;
    • Do not show the ID in browser now;
    • The user checks inbox and see your letter;
    • The user clicks the link and request is sent to your site confirmaion servlet;
    • Confirmation servlet will search for the account associated with the specified confirmation id;
    • Confirmaion servlet set account to "confirmed state" as obvously the user has access to the specified mail box
    0 讨论(0)
  • 2021-02-06 14:39

    Use Java Mail Api to create a e-mail with confirmation. Also, you need to generate unique id to confirm the user - this info can be stored in db. After the moment user clicks on your confirmation link you should set user in 'Confirmed' state.

    0 讨论(0)
提交回复
热议问题