【发布时间】:2020-03-23 19:29:42
【问题描述】:
仅当我尝试使用 javax 库发送邮件时才收到此错误。如果我从我的邮件客户端发送它,它工作正常。
Properties properties = new Properties();
properties.put("mail.transport.protocol", "smtp");
properties.put("mail.smtp.host",server); // smtp.gmail.com?
//properties.put("mail.smtp.port", "25");
properties.put("mail.smtp.auth", "true");
Authenticator authenticator = new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, pass);
}
};
Session session = Session.getDefaultInstance(properties, authenticator);
Message message =new MimeMessage(session);
message.setFrom(new InternetAddress("alert@test.com"));
message.setRecipients(Message.RecipientType.TO,InternetAddress.parse("alert1@test.com",false));
message.setSubject("test");
message.setText("hi");
Transport.send(message);
System.out.println("mail sernt");
我浏览了这些帖子,https://stackoverflow.com/questions/24688111/smtp-554-analysis,SMTP: Error 554, message is not RFC compliant, What does props.put("mail.smtp.host", host) in JavaMail do? 所有这些似乎都表明 IP 地址可能被阻止/与 SMTP 有关。但是,我的邮件客户端工作正常。这与 SMTP 配置有关还是我错过了什么。?
当我尝试调试时,我得到文件未找到异常:jre1.6.0\lib\javamail.providers 和 javamail.address.map。是否与这些异常有关。还有如何检查我的防火墙是否不是问题。
【问题讨论】:
-
放另一个属性
properties.put("mail.smtp.starttls.enable", "true"); -
@ricky2527 添加让我 javax 邮件异常:' javax.mail.MessagingException: Can't send command to SMTP host;嵌套异常是:javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException:PKIX 路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法找到请求目标的有效证书路径'
-
你可以在这里找到这个问题的解决方案。 stackoverflow.com/questions/14771061/…).