简体   繁体   English

javax.mail.MessagingException:PKIX 路径构建失败:SunCertPathBuilderException:无法找到请求目标的有效证书路径;

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

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.当我浏览论坛时,此错误的解决方案是将证书添加到使用的 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?问题是我对此并不陌生,我不确定我应该如何准确地做到这一点:我应该在哪里获得证书以及我应该如何添加它?

NB: I notice that when I run this using main method, it works fine, But when I set a Scheduler to call the method automatically.注意:我注意到当我使用 main 方法运行它时,它工作正常,但是当我设置调度程序以自动调用该方法时。 that's when I get the exception.那是我得到异常的时候。

Thank you a lot for the help.非常感谢您的帮助。

public void receiveMails() throws Exception
    {

        Properties props = new Properties();
        props.setProperty("mail.store.protocol", "imaps");
        props.setProperty("mail.imaps.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
        props.setProperty("mail.imaps.socketFactory.fallback", "false");
        props.setProperty("mail.imaps.ssl.enable", "false");
        props.setProperty("mail.imaps.socketFactory.port", "993");
        props.setProperty("mail.imaps.starttls.enable", "true");
        props.setProperty("mail.imaps.ssl.trust", "mailHost");

        try
        {
            
            Session session = Session.getInstance(props, null);
            Store store = session.getStore();
            store.connect("mailHost", "user@domain.com", "password");
//...

The Exception is:例外是:

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;
  nested exception is:
    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.imap.IMAPStore.protocolConnect(IMAPStore.java:479)
    at javax.mail.Service.connect(Service.java:275)
    at javax.mail.Service.connect(Service.java:156)
    

Try disabling your antivirus while doing this operation.尝试在执行此操作时禁用您的防病毒软件。 This might be the cause.这可能是原因。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PKIX 路径构建失败:SunCertPathBuilderException:无法找到到请求目标的有效认证路径 - PKIX path building failed: SunCertPathBuilderException: unable to find valid certification path to requested target SSLHandshakeException:PKIX 路径构建失败 SunCertPathBuilderException:无法找到请求目标的有效证书路径 - SSLHandshakeException: PKIX path building failed SunCertPathBuilderException: unable to find valid certification path to requested target PKIX 构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法找到请求目标的有效证书路径 - PKIX building failed:sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target CXF:PKIX 路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法找到请求目标的有效证书路径 - CXF:PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target PKIX路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法找到到请求目标的有效认证路径? - PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target? PKIX路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法找到到请求目标的有效认证路径 - PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target 无法找到到请求的目标PKIX路径构建的有效证书路径失败:sun.security.provider.certpath.SunCertPathBuilderException - unable to find valid certification path to requested target PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException JDK8-> JDK10:PKIX路径构建失败:SunCertPathBuilderException:无法找到到请求目标的有效证书路径 - JDK8 -> JDK10: PKIX path building failed: SunCertPathBuilderException: unable to find valid certification path to requested target PKIX 路径构建失败:SunCertPathBuilderException:无法找到请求的有效证书路径 - PKIX path building failed: SunCertPathBuilderException: unable to find valid certification path to requested PKIX路径构建失败:无法找到请求的目标的有效证书路径-导入的CERT - PKIX path building failed: unable to find valid certification path to requested target - imported CERT
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM