问题背景: 在本机写好了邮件发送的代码后,在本地测试时候是没有问题的,可是在部署了服务器之后,发现发送邮件的时候会一直报错,发送不了邮件。报的异常是 javax.mail.MessagingException:[EOF] java
![]()
Properties props = System.getProperties();
// 创建邮箱服务器端的链接
props.put("mail.smtp.host", EMAIL_HOST);
props.put("mail.smtp.port", PORT);
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
MailAuthenticatorEntity auth = new MailAuthenticatorEntity(EMAIL_FROM, AUTH_CODE);
Session session = Session.getDefaultInstance(props, auth);
MimeMessage message = new MimeMessage(session);
复制代码
在代码中加入了一行 props.put("mail.smtp.starttls.enable", "true");bash