First, demand
In the project, we often need to use the phone number / email to register, login or retrieve your password, this time on the need to send a verification code! Here I will teach you how to use java to the mailbox to send a verification code.
1, you first need mailUtils Tools
The principal tool used to encapsulate the transmission information parameters Mailbox
2, EmailService class
3, EmailServiceImpl implementation class
Five-digit random number generation, the Internet there are many ways we can find their own, there is not demonstrated.
When @Asyns ( "taskExecutor") notes asynchronous implementation will mean sendEmail method to send mail using the thread pool
thread pool configuration
4、sendCode controller类
5, test
Test postman in! !
Then mailbox will receive, retrieve the password verification code notice. Similarly other types of codes.
This is to send a verification email with a simple java code information of the matter, which involves a logical decision (to send a verification code in a different type), this is not to show, you can go think about it! ! To learn more, always more training and benefits.