Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JavaMail with SSL and TLS

843834Jul 28 2008 — edited Jul 28 2008
Hi All,

I am trying to connect to a mail server which is configured for POP3 access using SSL/TLS and cleartext login.

I have tried using the following code:
    
   public void connect() {
        try {
            Properties props = System.getProperties();

            Session session = Session.getDefaultInstance(props, new MailAuthenticator());
            store = session.getStore("pop3s");
                
            store.connect(popServer, popPort, popUser, popPassword);

            folder = store.getDefaultFolder();
            if (folder == null) {
                throw new Exception("No default folder");
            }

            folder = folder.getFolder("INBOX");

            if (folder == null) {
                throw new Exception("No POP3 INBOX");
            }

            folder.open(Folder.READ_ONLY);

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    
    private class MailAuthenticator extends Authenticator{
        MailAuthenticator(){
            super();
        }
    }
But this just brings back the error:

javax.mail.MessagingException: Connect failed;
nested exception is: javax.net.ssl.SSLHandshakeException:
sun.security.validator.ValidatorException: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at
com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:148) at
javax.mail.Service.connect(Service.java:275) at
EMail.Pop3Retreiver.connect(Pop3Retreiver.java:128)

I have installed a certificate using the java keytool and the certificate is visible when you go to control panel and java|security.

Any ideas what i'm missing here as i have read the SSLNotes.txt and can't seem to get any further on this.

Help is appreciated.

Regards
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 25 2008
Added on Jul 28 2008
1 comment
299 views