1、导入依赖
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>4.5.15</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
</dependency>
2、resource/config 目录下创建 mail.setting 文件
# 邮件服务器的SMTP地址,可选,默认为smtp.<发件人邮箱后缀>
host = smtp.exmail.qq.com
# 邮件服务器的SMTP的端口
port = 465
# 发件人(必须正确,否则发送失败)
from = xxx@corp.xxx.com
# 密码
pass = (百度客户端授权码设置)
# 用户 (注意,这里一定要和发件人一致)
user = xxx@corp.xxx.com
# 使用SSL安全连接
sslEnable = true
3、发送邮件
MailUtil.send("hutool@foxmail.com", "测试", "邮件来自Hutool测试", false);