java通过网易邮箱发送邮件
首先申请网易邮箱后开启POP3/SMTP服务,会获得一个授权码
通过hutool工具发送邮件
需要添加的依赖
<dependency><groupId>javax.mail</groupId><artifactId>mail</artifactId><version>5.5.7</version></dependency><dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>1.4.7</version></dependency>
代码实现
private String from = "wangpeng1172@";private String host = "";// 开启POP3/SMTP服务获取的授权码,不同于邮箱密码private String password = "TPORTDOYSZFSJOZP4";private Integer port = 465;public void sendMail(String to, String title, String content) {MailAccount account = new MailAccount();account.setFrom(from);account.setHost(host);account.setPass(password);account.setPort(port);account.setSslEnable(true);// 群发选项List<String> tos = new ArrayList<>();tos.add(to);MailUtil.send(account, tos, title, content, false);}