gpt4 book ai didi

Java 电子邮件 - 异常服务器不受信任

转载 作者:行者123 更新时间:2023-12-03 19:11:26 28 4
gpt4 key购买 nike

我正在使用 apache commons mail 发送电子邮件。不幸的是,我遇到了以下异常:

org.apache.commons.mail.EmailException: Sending the email to the following server failed : mail.xxx.com:25
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1242)
at org.apache.commons.mail.Email.send(Email.java:1267)
at com.xxx.UserBean.sendMail(UserBean.java:92)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
.
.
.
Caused by: javax.mail.MessagingException: Could not convert socket to TLS;
nested exception is:
java.io.IOException: Server is not trusted: mail.xxx.com
at com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:1880)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:648)
at javax.mail.Service.connect(Service.java:317)
at javax.mail.Service.connect(Service.java:176)
at javax.mail.Service.connect(Service.java:125)
at javax.mail.Transport.send0(Transport.java:194)
at javax.mail.Transport.send(Transport.java:124)
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1232)
... 85 more
Caused by: java.io.IOException: Server is not trusted: mail.xxx.com
at com.sun.mail.util.SocketFetcher.startTLS(SocketFetcher.java:443)
at com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:1875)
... 92 more

这是我的java代码:

    public void sendMail(){
try {
SimpleEmail mail = new SimpleEmail();
mail.setTLS(true);
mail.setAuthenticator(new DefaultAuthenticator("user","xyxyxyxy"));
mail.setHostName("mail.xxx.com");
mail.getMailSession().getProperties().put("mail.smtps.auth", true);
mail.getMailSession().getProperties().put("mail.debug", true);
mail.getMailSession().getProperties().put("mail.smtps.port", "587");
mail.getMailSession().getProperties().put("mail.smtp.starttls.enable", true);
mail.getMailSession().getProperties().put("mail.smtp.ssl.trust", "smtpserver");

mail.addTo("user@server.com", "user");
mail.setFrom("info@xxx.com");
mail.setSubject("Bla Bla");
mail.setMsg("Bla Bla again");
mail.send();
} catch (Exception ex) {
logger.info("Senden der Email ist gescheitert!", ex);
}
}

我已经阅读了许多主题并尝试了许多提示。我被困在这里了!我应该提一下,我可以使用“javax.mail”通过另一种方法发送电子邮件。但我想搬到 apache。

感谢您的帮助。

最佳答案

将TLS(传输层安全)设置为 false。如果你不使用。当它为 true 时,它​​应该是 mail.xxx.com 受信任的服务器。

mail.setTLS(false);

关于Java 电子邮件 - 异常服务器不受信任,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13918374/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com