0

I have JAVA application which work as service on Tomcat server. I need to develope service for receiving mail from GMAIL pop3 server. I use Javamail. I have written usual code, but when I deploy it on server I am getting

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

As for development my Tomcat started on Localhost.
And this problemm looks like concerned with certificate.

My code is

    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();
        }
    }

I am getting exception on line store.connect(username, password);

I use properties:

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

Please help me to solve this problem. I never worked with Tomcat and certificates before!

user207421
  • 305,947
  • 44
  • 307
  • 483
MichaelZal
  • 21
  • 6
  • Possible duplicate of [Unable to find valid certification path to requested target - error even after cert imported](https://stackoverflow.com/questions/9210514/unable-to-find-valid-certification-path-to-requested-target-error-even-after-c) – user207421 Aug 27 '19 at 20:32
  • See this [JavaMail FAQ entry](https://javaee.github.io/javamail/FAQ#installcert). – Bill Shannon Aug 27 '19 at 20:33

0 Answers0