Code example of sending mail based on SSM framework + JavaMail
This article introduces the JavaMail application based on the combination of SSM framework (spring 4.0 + spring MVC + mybatis). If the mailbox is based on Tencent's QQ mailbox, it is also Foxmail mailbox
First, we need to understand the SMTP protocol and SSL encryption
SMTP: called simple mail transfer protocol, it aims to provide users with efficient and reliable mail transmission. SMTP is a request response protocol, that is, the client sends a request to the remote server, the server responds, and the listening port is 25. Therefore, it has two working modes: sending SMTP and receiving SMTP.
SSL encryption: used to ensure the security of browsers and web servers. Its principle is explained in Translation:
When your browser requests a secure web page from the server (usually HTTPS: / /)
The server sends back its certificate and public key
The browser checks whether the certificate is issued by a trusted organization, and confirms that the certificate is valid and belongs to this website.
A random symmetric key is encrypted with the public key and sent to the server together with the encrypted URL
The server decrypted the key you sent with its own private key. Then use this symmetric encryption key to decrypt the URL link you requested.
The server uses the symmetric key you sent to encrypt the web page you requested. You also have the same key to decrypt the web page sent back
Then it introduces how to send mail by JavaMail. First, download the jar of JavaMail: http://xiazai.jb51.net/201612/yuanma/mail_jb51.jar
Go to the QQ mailbox serving as the server and start the SMTP service:
Write a business class to send mail:
Then write a controller class of the spring MVC framework:
Here, the jQuery tip plug-in is used for verification prompt, so the corresponding jQuery file needs to be introduced
JQuery form validation and Ajax asynchronous requests:
Call of JSP page:
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.