java如何实现QQ邮箱验证

这里后台用的是spring boot。

       实现QQ邮箱验证首页添加依赖:

         <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>

       之后在application.properties配置文件中添加配置:

        #设置字符集

        spring.mail.default-encoding=UTF-8
        spring.mail.host=smtp.qq.com
        #发送者的邮箱密码
        spring.mail.password=hifkmndzrknnbdjf
        #端口
        spring.mail.port=587
        #协议
        spring.mail.protocol=smtp
        #发送者的邮箱账号
        [email protected]

        最后写java代码:

        //发送者的邮箱账号
       @Value("${spring.mail.username}")
       private String mailusername;
       @Autowired
       JavaMailSender jms;

         //建立邮件消息
        SimpleMailMessage mainMessage = new SimpleMailMessage();
        //发送者
        mainMessage.setFrom(mailusername);
        //接收者
        mainMessage.setTo(username);
        //发送的标题
        mainMessage.setSubject("电子发票管理系统");
        String code = VerifyCodeUtils.generateVerifyCode(6);
        //发送的内容
        mainMessage.setText("请记住验证码:"+code);
        jms.send(mainMessage);

OK了,java实现QQ邮箱验证。

     

猜你喜欢

转载自blog.csdn.net/qq_40205116/article/details/83932316