gpt4 book ai didi

java - 使用 commons-mail 在 Java 中发送电子邮件

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:42:43 25 4
gpt4 key购买 nike

所以我正在尝试使用 Java 将代码发送到我的电子邮件。我从 javax.mail 开始,但记得我上次使用它时遇到了问题,所以我转向了 Apache Commons Mail。

不过我遇到了一堆错误。在 SSL 上,我收到了 java.net.SocketTimeoutException,在 TLS 上,我收到了一些错误:

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:2000)

Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

当我快速进行 Google 搜索时,我找到了 this question .现在因为我是个彻头彻尾的白痴,所以我不明白答案。

我该怎么做才能解决这些错误?无论是防止 SSL 超时还是 TLS 上的其他超时。

编辑:我发送电子邮件没有问题,MessageException 不是我的问题所以请停止回答。

最佳答案

Email email = new SimpleEmail();
...

// add this line
email.getMailSession().getProperties().put("mail.smtp.ssl.trust", "smtp.gmail.com");

...
email.send();

关于java - 使用 commons-mail 在 Java 中发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31338015/

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