网易企业邮箱
SMTP: smtphz.qiye.163.com 25(不加密) 994(加密)
spring boot配置1
2
3
4
5
6
7
8
9
10
11
12spring:
mail:
host: smtphz.qiye.163.com
port: 994
username: xxxxxx
password: xxxxxx
properties:
"mail.smtp.auth": true
"mail.smtp.ssl.enable": true
"mail.smtp.starttls.enable": false
"mail.smtp.starttls.required": false
"mail.debug": true
发送邮件代码1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23@Autowired
private JavaMailSender mailSender;
@Value("${spring.mail.username}")
private String from;
String to = "xxx@example.com";
String code = "1234";
MimeMessage message = mailSender.createMimeMessage();
try {
message.setFrom(new InternetAddress(from));
message.setRecipients(MimeMessage.RecipientType.TO, to);
final String subject = "Verification\u00A0Code";
final String html = "<p>Your verification code is :</p>" +
"<h1>${code}</h1>" +
"<p>Please enter it within 5 minutes.</p>";
message.setSubject(subject);
message.setContent(html.replace("${code}", code), "text/html; charset=utf-8");
} catch (MessagingException e) {
throw new ApiException(500, "send mail failed.");
}
mailSender.send(message);
备注:
阿里云不允许25端口发送邮件
本文标题:spring boot网易企业邮箱发邮件
本文链接:https://xxzkid.github.io/2024/spring-boot-163qy-mail/