0

我有在 Tomcat 服务器上作为服务工作的 JAVA 应用程序。我需要开发从 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(username, password);线上遇到异常

我使用属性:

mail.pop3.host=pop.gmail.com
mail.pop3.port=995
mail.pop3.ssl.enable=true
mail.pop3.protocol=pop3
mail.pop3.inbox=INBOX

请帮我解决这个问题。我以前从未使用过 Tomcat 和证书!

4

0 回答 0