【一文轻松搞懂Java自动发送邮件的功能】

第一步:新建项目

项目结构:

第二步:申请邮箱的授权码

第三步:完成配置文件和maven依赖

properties.yml

pom.xml

<!--javaweb-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

<!--springboot邮件-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-mail</artifactId>
</dependency>

<!--模版引擎-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

第四步:完成controller

具体步骤和每一步都是什么意思,代码注释的很清楚,我相信小学生也可以看懂

MailController.java

第五步:结果展示

1、浏览器输入:http://localhost:8089/send >
2、浏览器输入:http://localhost:8089/sendHtml
3、浏览器输入:http://localhost:8089/sendHtmlAndAttachment
经验分享 程序员 微信小程序 职场和发展