javax.mail.MessagingException: PKIX path building failed: SunCertPathBuilderException: unable to find valid certification path to requested target;

huangapple go评论97阅读模式
英文:

javax.mail.MessagingException: PKIX path building failed: SunCertPathBuilderException: unable to find valid certification path to requested target;

问题

我在尝试连接到存储时遇到了这个异常。

当我查看论坛时,发现解决这个错误的方法是将证书添加到正在使用的 JVM 的信任存储文件中。

问题是我是新手,不太确定我应该如何做到这一点:我应该从哪里获取证书,如何添加它?

注:我注意到当我使用主方法运行它时,它可以正常工作!但当我设置一个调度程序来自动调用该方法时,我就会遇到这个异常。

非常感谢帮助。

异常是:

  1. javax.mail.MessagingException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target;
  2. nested exception is:
  3. 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
  4. at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:479)
  5. at javax.mail.Service.connect(Service.java:275)
  6. at javax.mail.Service.connect(Service.java:156)

以下是代码部分,无需翻译:

  1. public void receiveMails() throws Exception
  2. {
  3. Properties props = new Properties();
  4. props.setProperty("mail.store.protocol", "imaps");
  5. props.setProperty("mail.imaps.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
  6. props.setProperty("mail.imaps.socketFactory.fallback", "false");
  7. props.setProperty("mail.imaps.ssl.enable", "false");
  8. props.setProperty("mail.imaps.socketFactory.port", "993");
  9. props.setProperty("mail.imaps.starttls.enable", "true");
  10. props.setProperty("mail.imaps.ssl.trust", "mailHost");
  11. try
  12. {
  13. Session session = Session.getInstance(props, null);
  14. Store store = session.getStore();
  15. store.connect("mailHost", "user@domain.com", "password");
  16. //...
  17. }
  18. }
英文:

I get this Exception when I try to connect to the store.

As I look through forums, the solution to this error is to add the certificate to the truststore file of the used JVM.

The problem is I am new to this and I am not sure that I understand how I should do this exactly: Where should I get the certificate and how should I add it?

N.B: I notice that when I run this using main method, it works fine! But when I set a Scheduler to call the method automatically, that's when I get the exception.

Thank you a lot for the help.

  1. public void receiveMails() throws Exception
  2. {
  3. Properties props = new Properties();
  4. props.setProperty("mail.store.protocol", "imaps");
  5. props.setProperty("mail.imaps.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
  6. props.setProperty("mail.imaps.socketFactory.fallback", "false");
  7. props.setProperty("mail.imaps.ssl.enable", "false");
  8. props.setProperty("mail.imaps.socketFactory.port", "993");
  9. props.setProperty("mail.imaps.starttls.enable", "true");
  10. props.setProperty("mail.imaps.ssl.trust", "mailHost");
  11. try
  12. {
  13. Session session = Session.getInstance(props, null);
  14. Store store = session.getStore();
  15. store.connect("mailHost", "user@domain.com", "password");
  16. //...

The Exception is:

  1. javax.mail.MessagingException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target;
  2. nested exception is:
  3. 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
  4. at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:479)
  5. at javax.mail.Service.connect(Service.java:275)
  6. at javax.mail.Service.connect(Service.java:156)

答案1

得分: 2

尝试在进行此操作时禁用您的防病毒软件。这可能是问题的原因。

英文:

Try disabling your antivirus while doing this operation. This might be the cause.

huangapple
  • 本文由 发表于 2020年8月5日 01:02:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/63251729.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定