how to ignore server cert error in javamail

后端 未结 10 1317
长发绾君心
长发绾君心 2020-12-05 07:12

when i connect to my imap server using imaps,it failes.

can you tell me how to ignore server cert error in javamail

Exception in thread \"main\"
java         


        
相关标签:
10条回答
  • 2020-12-05 08:04

    If It is the problem persisted in Java 6 then the solution is simple.It is just simple as Java 7 was released.Install java 7 in machine.java 7 have the certificates file having the capability of ignoring certificate authentication.

    copy the "cacerts" file from following java 7 directory

    C:\Program Files\Java\jdk1.7.0_79\jre\lib\security

    and paste it in

    C:\Program Files\Java\jdk1.6.0\jre\lib\security

    now the certificate authentication problem will be resolved.

    0 讨论(0)
  • 2020-12-05 08:07

    I was the same issue.

    MailSSLSocketFactory socketFactory = new MailSSLSocketFactory(); socketFactory.setTrustedHosts(new String[] { "my-server"});

    socketFactory.setTrustAllHosts(true); props.put("mail.smtps.socketFactory", socketFactory);

    it's works!!

    0 讨论(0)
  • 2020-12-05 08:09

    use prop.put("mail.imaps.ssl.trust", "*"); since you are using imaps store.

    and for smtp you can try : prop.put("mail.smtp.ssl.trust", "*"); .

    0 讨论(0)
  • 2020-12-05 08:09
         Properties propsSSL = new Properties();
         propsSSL.put("mail.transport.protocol", "smtps");
         propsSSL.put("mail.smtps.host", "hostname");
         propsSSL.put("mail.smtps.auth", "true");
         propsSSL.put("mail.smtps.ssl.checkserveridentity", "false");
         propsSSL.put("mail.smtps.ssl.trust", "*");
    

    Above changes will fix javax.mail.MessagingException: Could not connect to SMTP host: hostname, port: 465; for the nested exception

    javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path validation failed: java.security.cert.CertPathValidatorException: Path does not chain with any of the trust anchors
    exception 
    
    0 讨论(0)
提交回复
热议问题