引入Hutool依赖 !--邮箱验证hutool-- dependency groupIdcn.hutool/groupId artifactIdhutool-all/artifactId version4.6.3/version /dependency dependency groupIdjavax.mail/groupId artifactIdmail/artifactId version1.4.7/version /dependency 配
引入Hutool依赖
<!--邮箱验证hutool--> <dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> <version>4.6.3</version> </dependency> <dependency> <groupId>javax.mail</groupId> <artifactId>mail</artifactId> <version>1.4.7</version> </dependency>
配置mail.setting文件
# 邮件服务器的SMTP地址,可选,默认为smtp.<发件人邮箱后缀> host = smtp.yeah.net # 邮件服务器的SMTP端口,可选,默认25 port = 25 # 发件人(必须正确,否则发送失败) from = [email protected] # 用户名,默认为发件人邮箱前缀 user = hutool # 密码(注意,某些邮箱需要为SMTP服务单独设置密码,详情查看相关帮助) pass = q1w2e3
编写测试类
public class MailTest { public static void main(String[] args) { MailUtil.sendText("你要发送的邮箱","邮件标题","内容"); } }
详情请点击:https://www.hutool.cn/docs/#/extra/%E9%82%AE%E4%BB%B6%E5%B7%A5%E5%85%B7-MailUtil