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

本文介绍如何使用Spring Boot项目集成QQ邮箱服务实现邮件发送功能。包括项目的搭建、依赖引入、配置文件设置、获取授权码及代码实现等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

1.创建spring boots项目:

a.

b

c

d

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

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

3配置

     

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.

b.

c.

d.

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

5.@Autowired
    private JavaMailSender mailSender;

 /**
     * 验证email
     */
    @RequestMapping("yzemail")
    @ResponseBody
    public boolean yzemail(User user){
        System.out.print(user.getEmail());
        try {
            SimpleMailMessage message = new SimpleMailMessage();
            message.setFrom("xx@qq.com");
            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"
                    )

            })

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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

LLY-yy

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值