Javamail java.security.cert.CertPathValidatorException从pop3接收邮件时

问题描述:

所以我试图建立一个Android应用程序,从我的大学的服务器cheks电子邮件。它适用于Gmail。 我添加的证书(.CER文件)密钥库,我试着用以下属性:Javamail java.security.cert.CertPathValidatorException从pop3接收邮件时

 Properties properties = new Properties(); 
     properties.put("mail.store.protocol", "pop3"); 
     properties.put("mail.pop3.host", pop3Host); 
     properties.put("mail.pop3.port", "995"); 
     properties.put("mail.pop3.starttls.enable", "true"); 
     properties.put("mail.pop3.ssl.checkserveridentity", "false"); 
     properties.put("mail.pop3.ssl.trust", "*"); 
     Session emailSession = Session.getDefaultInstance(properties); 

...并没有什么:(

DEBUG:

stefan.studmail I/System.out﹕ DEBUG: setDebug: JavaMail version 1.5.3 
stefan.studmail I/System.out﹕ DEBUG: getProvider() returning javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle] 
stefan.studmail W/art﹕ Before Android 4.1, method javax.mail.Session com.sun.mail.pop3.POP3Store.getSession() would have incorrectly overridden the package-private method in javax.mail.Service 
stefan.studmail I/System.out﹕ DEBUG POP3: mail.pop3s.rsetbeforequit: false 
stefan.studmail I/System.out﹕ DEBUG POP3: mail.pop3s.disabletop: false 
stefan.studmail I/System.out﹕ DEBUG POP3: mail.pop3s.forgettopheaders: false 
stefan.studmail I/System.out﹕ DEBUG POP3: mail.pop3s.cachewriteto: false 
stefan.studmail I/System.out﹕ DEBUG POP3: mail.pop3s.filecache.enable: false 
stefan.studmail I/System.out﹕ DEBUG POP3: mail.pop3s.keepmessagecontent: false 
stefan.studmail I/System.out﹕ DEBUG POP3: mail.pop3s.starttls.enable: false 
stefan.studmail I/System.out﹕ DEBUG POP3: mail.pop3s.starttls.required: false 
stefan.studmail I/System.out﹕ DEBUG POP3: mail.pop3s.apop.enable: false 
stefan.studmail I/System.out﹕ DEBUG POP3: mail.pop3s.disablecapa: false 
stefan.studmail I/System.out﹕ DEBUG POP3: connecting to host "stud.usv.ro", port 995, isSSL true 
stefan.studmail I/Timeline﹕ Timeline: Activity_idle id: [email protected] time:14882263 
stefan.studmail E/StudMail:﹕ Connect failed 
stefan.studmail W/System.err﹕ javax.mail.MessagingException: Connect failed; 
stefan.studmail W/System.err﹕ nested exception is: 
stefan.studmail W/System.err﹕ javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. 
stefan.studmail W/System.err﹕ at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:213) 
stefan.studmail W/System.err﹕ at javax.mail.Service.connect(Service.java:364) 
stefan.studmail W/System.err﹕ at javax.mail.Service.connect(Service.java:245) 
stefan.studmail W/System.err﹕ at senegeac.stefan.studmail.FetchPop.fetch(FetchPop.java:75) 
stefan.studmail W/System.err﹕ at senegeac.stefan.studmail.FetchPop.doInBackground(FetchPop.java:145) 
stefan.studmail W/System.err﹕ at senegeac.stefan.studmail.FetchPop.doInBackground(FetchPop.java:39) 
stefan.studmail W/System.err﹕ at android.os.AsyncTask$2.call(AsyncTask.java:297) 
stefan.studmail W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
stefan.studmail W/System.err﹕ at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) 
stefan.studmail W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
stefan.studmail W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
stefan.studmail W/System.err﹕ at java.lang.Thread.run(Thread.java:818) 
stefan.studmail W/System.err﹕ Caused by: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. 
stefan.studmail W/System.err﹕ at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:306) 
stefan.studmail W/System.err﹕ at com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:574) 
stefan.studmail W/System.err﹕ at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:369) 
stefan.studmail W/System.err﹕ at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:236) 
stefan.studmail W/System.err﹕ at com.sun.mail.pop3.Protocol.<init>(Protocol.java:112) 
stefan.studmail W/System.err﹕ at com.sun.mail.pop3.POP3Store.getPort(POP3Store.java:264) 
stefan.studmail W/System.err﹕ at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:207) 
stefan.studmail W/System.err﹕ ... 11 more 
stefan.studmail W/System.err﹕ Caused by: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. 
stefan.studmail W/System.err﹕ at com.android.org.conscrypt.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:323) 
stefan.studmail W/System.err﹕ at com.android.org.conscrypt.TrustManagerImpl.checkServerTrusted(TrustManagerImpl.java:224) 
stefan.studmail W/System.err﹕ at com.android.org.conscrypt.Platform.checkServerTrusted(Platform.java:113) 
stefan.studmail W/System.err﹕ at com.android.org.conscrypt.OpenSSLSocketImpl.verifyCertificateChain(OpenSSLSocketImpl.java:525) 
stefan.studmail W/System.err﹕ at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method) 
stefan.studmail W/System.err﹕ at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:302) 
stefan.studmail W/System.err﹕ ... 17 more 
stefan.studmail W/System.err﹕ Caused by: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. 
stefan.studmail W/System.err﹕ ... 23 more 

尝试使用Session.getInstance

如果没有帮助,请发送debug output

+0

尝试getInstance并没有任何东西。增加了调试日志,并尝试将属性中的pop3更改为pop3s,并且它在调试中仍然显示为false。 – ogrishmania

+0

您认为您将“mail.pop3s.starttls.enable”属性设置为“true”,但调试输出清楚地表明它是错误的。你仍然在做错什么,但从你向我们展示的东西我不知道它是什么。 –