2015-06-20 5 views
0

Итак, я пытаюсь создать приложение для Android, которое отправляет электронную почту с сервера моего университета. Он отлично работает с Gmail. Я добавил сертификат (файл .cer) в KeyStore, я пытался со следующими свойствами: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», но вывод отладки явно показывает, что он является ложным. Вы все еще делаете что-то не так, но из того, что вы нам показали, я не могу сказать, что это такое. –