SpingBoot+Freemarker实现5种发送邮件

本文通过SpringBoot展示了使用Freemarker模板发送邮件的5种方法,包括配置QQ邮箱开启SMTP服务,获取授权码,添加相关依赖,设置application.properties文件,创建Pojo,以及在resources下创建Freemarker和Thymeleaf模板。
摘要由CSDN通过智能技术生成

SpingBoot___5种简单的发生邮件的小demo

过程图
在这里插入图片描述

这里使用的是qq邮箱,先去你的qq邮箱开启SMIP和POP3
在这里插入图片描述
然后它会叫你发短信拿授权码,那个授权码需要记住,后面有用。

依赖

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

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

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

application.properties

#配置 SMTP 服务器地址
spring.mail.host=smtp.qq.com
#SMTP 服务器的端口
spring.mail.port=587
#配置邮箱用户名
spring.mail.username=发送者@qq.com
#申请到的授权码
spring.mail.password=授权码
#默认的邮件编码
spring.mail.default-encoding=UTF-8
#配饰 SSL 加密工厂
spring.mail.properties.mail.smtp.socketFactoryClass=javax.net.ssl.SSLSocketFactory
#表示开启 DEBUG 模式
spring.mail.properties.mail.debug=true

Pojo

/**
 *
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

偷偷学习被我发现

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

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

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

打赏作者

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

抵扣说明:

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

余额充值