我有JAVA应用程序,可以在Tomcat服务器上作为服务使用。我需要开发用于从GMAIL pop3服务器接收邮件的服务。我使用Javamail。我已经编写了通常的代码,但是当我将其部署在服务器上时,我会得到
javax.mail.MessagingException: Connect failed;
nested exception is:
javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
关于开发,我的Tomcat在Localhost上启动。
而且这个问题看起来与证书有关。
我的代码是
public void downloadMail() {
try {
// connects to the message store and opens the inbox folder
Store store = session.getStore(protocol);
store.connect(username, password);
Folder folderInbox = store.getFolder(inbox);
folderInbox.open(Folder.READ_WRITE);
// fetches new messages from server
Message[] messages = folderInbox.getMessages();
for (int i = 0; i < messages.length; i++) {
Mail mail = extractMail(messages[i]);
messages[i].setFlag(Flags.Flag.DELETED, true);
}
// disconnect
folderInbox.close(false);
store.close();
} catch (NoSuchProviderException ex) {
System.out.println( "No provider for pop3.");
ex.printStackTrace();
} catch (MessagingException ex) {
System.out.println( "Could not connect to the message store");
ex.printStackTrace();
} catch (IOException ex) {
System.out.println( "Can not save file or open directory");
ex.printStackTrace();
}
}
我在 store.connect(用户名,密码);行上遇到异常
我使用属性:
mail.pop3.host=pop.gmail.com
mail.pop3.port=995
mail.pop3.ssl.enable=true
mail.pop3.protocol=pop3
mail.pop3.inbox=INBOX
请帮助我解决此问题。我以前从未使用过Tomcat和证书!