Teach you how to send a different message authentication code to the mailbox using java! ! ! Use springboot framework

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 MailboxHere Insert Picture Description
Here Insert Picture Description

2, EmailService class

Here Insert Picture Description

3, EmailServiceImpl implementation class

Five-digit random number generation, the Internet there are many ways we can find their own, there is not demonstrated. Here Insert Picture Description
When @Asyns ( "taskExecutor") notes asynchronous implementation will mean sendEmail method to send mail using the thread pool
Here Insert Picture Description
thread pool configuration
Here Insert Picture Description

4、sendCode controller类

Here Insert Picture Description

5, test

Test postman in! !
Here Insert Picture Description
Then mailbox will receive, retrieve the password verification code notice. Similarly other types of codes.
Here Insert Picture Description
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.

Guess you like

Origin blog.csdn.net/qq_43419029/article/details/89236187