spring boots项目:向qq邮箱发送短信

做一个向QQ邮箱发送验证的项目:

1.创建spring boots项目:

a.

spring boots项目:向qq邮箱发送短信

b

spring boots项目:向qq邮箱发送短信

c

spring boots项目:向qq邮箱发送短信

d

spring boots项目:向qq邮箱发送短信

2.创建完项目后:在pom.xml中加入依赖:

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

3配置spring boots项目:向qq邮箱发送短信

     

spring.datasource.url=jdbc:mysql://localhost:3306/数据库名
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

# 前后缀

spring.mvc.view.suffix=.jsp


spring.mvc.view.prefix=/jsp/

spring.mail.host=smtp.qq.com
# //发送方的邮箱
spring.mail.username=自己的@qq.com
# //对于qq邮箱而言 密码指的就是发送方的授权码
spring.mail.password=下一步解释

# 下面三条默认打开无需修改
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true

4.获取QQ的授权密码:

a.

spring boots项目:向qq邮箱发送短信

b.

spring boots项目:向qq邮箱发送短信

c.

spring boots项目:向qq邮箱发送短信

d.

spring boots项目:向qq邮箱发送短信

e.发送完成点击我已发送,,会有一个16位的授权码,填入上一步的密码部分.....

[email protected]
    private JavaMailSender mailSender;

 /**
     * 验证email
     */
    @RequestMapping("yzemail")
    @ResponseBody
    public boolean yzemail(User user){
        System.out.print(user.getEmail());
        try {
            SimpleMailMessage message = new SimpleMailMessage();
            message.setFrom("[email protected]");
            message.setTo(user.getEmail());
            message.setSubject("主题:简单邮件");
            message.setText("测试邮件内容");
            mailSender.send(message);
            return true;
        }catch (Exception e){
            System.out.print(e.getMessage());
            return false;
        }

    }

6. <tr>
            <td>email<input type="text" name="email"></td>
        </tr>

 $("[name='email']").change(function(){
                var email=$("[name='email']").val();


                    $.post(
                        "<%=request.getContextPath() %>/yzemail",
                        {email:email},
                        function(obj){
                            alert(obj);
                        },"json"
                    )

            })

此处为内容改变事件,可以按需求自己调整.

新手求指教,来大神带飞!!!!感谢