2015-06-20 91 views
0

所以我試圖建立一個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 

回答

0

嘗試使用Session.getInstance

如果沒有幫助,請發送debug output

+0

嘗試getInstance並沒有任何東西。增加了調試日誌,並嘗試將屬性中的pop3更改爲pop3s,並且它在調試中仍然顯示爲false。 – ogrishmania

+0

您認爲您將「mail.pop3s.starttls.enable」屬性設置爲「true」,但調試輸出清楚地表明它是錯誤的。你仍然在做錯什麼,但從你向我們展示的東西我不知道它是什麼。 –