You may come across mailbox validation as a feature during Java development

For example: 1) You may need to use email authentication when you register your business; 2) You may also need to use email authentication when you retrieve your password

So how does this function work?

Tool: Commons – Email JAR package

The first step:

Before sending the verification code by email, you should first open the POP3/SMTP service and IMAP/SMTP service of your mailbox

Here we take mailbox netease 126 as an example:

The second step:

  • Create an HtmlEmail instance object

    Email email=new SimpleEmail();
    
  • Set up the SMTP server of the mailbox, log in the corresponding mailbox official website, and find the corresponding one in the picture above

    email.setHostName("smtp.126.com"); // The SMTP server for your mailbox is smtp.126.com and smtp.qq.com
  • Sets the type of character set to send

    email.setCharset("utf-8");
    
  • Setting Recipient

    email.addTo("[email protected]"); / / the recipient
  • Set the sender’s mailbox and user name

    email.setFrom("[email protected]","lss"); // From the sender, you can fill in any username
  • Set the CC side

    email.addCc("[email protected]"); / / cc
  • Set email address and authorization code

    email.setAuthentication("[email protected]","xxxxxxxxxxxxxxxx"); // Your email address and your STMP authorization code
  • Set Email Subject

    HtmlEmail.setSubject (" Captcha test message ");
  • Set the content of the email (don’t make it too simple, you might end up in the recipient’s spam inbox)

    SetMsg (" Hello,This is a test mail... , verification code: 9527");
  • Send E-mail

    email.send();

Step 3:

Test results: