问题描述
我使用的是在线找到的类FetchingEmails,以查看是否可以在Eclipse上使用它。这是我得到的错误: javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException:PKIX路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法找到到请求目标的有效证书路径
正如其他一些解决方案所建议的那样,我尝试将gmail证书的副本从浏览器下载到我的本地计算机,并使用以下命令将其导入。但是我仍然遇到相同的错误。
keytool -import -file <the cert file> -alias <some meaningful name> -keystore <path to cacerts file>
我对证书了解不多。我相应地更改了凭据。以下是我发现的部分代码。感谢您的帮助和建议。
public static void fetch(String pop3Host,String storeType,String user,String password) {
try {
// create properties field
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");
Session emailSession = Session.getDefaultInstance(properties);
// emailSession.setDebug(true);
// create the POP3 store object and connect with the pop server
Store store = emailSession.getStore("pop3s");
store.connect(pop3Host,user,password);
// create the folder object and open it
Folder emailFolder = store.getFolder("INBox");
emailFolder.open(Folder.READ_ONLY);
BufferedReader reader = new BufferedReader(new InputStreamReader(
system.in));
// retrieve the messages from the folder in an array and print it
Message[] messages = emailFolder.getMessages();
System.out.println("messages.length---" + messages.length);
for (int i = 0; i < messages.length; i++) {
Message message = messages[i];
System.out.println("---------------------------------");
writePart(message);
String line = reader.readLine();
if ("YES".equals(line)) {
message.writeto(System.out);
} else if ("QUIT".equals(line)) {
break;
}
}
// close the store and folder objects
emailFolder.close(false);
store.close();
} catch (NoSuchProviderException e) {
e.printstacktrace();
} catch (MessagingException e) {
e.printstacktrace();
} catch (IOException e) {
e.printstacktrace();
} catch (Exception e) {
e.printstacktrace();
}
}
public static void main(String[] args) {
String host = "pop.gmail.com";// change accordingly
String mailStoreType = "pop3";
String username =
"abc@gmail.com";// change accordingly
String password = "*****";// change accordingly
//Call method fetch
fetch(host,mailStoreType,username,password);
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)