1

Javamail を使用して Gmail アカウントに接続しようとしています。接続されず、エラーがスローされます。ここに私のコードがあります -

public class MailConnection {
    Folder inbox;

public MailConnection() throws MessagingException{
    Properties props = System.getProperties();
    props.setProperty("mail.store.protocol", "imaps");
    props.setProperty("mail.imap.starttls.enable", "true");
    props.setProperty("mail.imap.ssl.enable", "true");
     try{
         Session session = Session.getInstance(props, null);
         session.setDebug(true);
         Store store = session.getStore("imaps");
         store.connect("mailbox.xyz.com", "emailId@xyz.com", "password");
         System.out.println(store);

         inbox = store.getFolder("Inbox");
         System.out.println("No of Unread Messages : " + inbox.getUnreadMessageCount());
     }
     catch (NoSuchProviderException e){
        e.printStackTrace();
        System.exit(1);
     }
}

上記のコードを実行すると、デバッグ出力とエラーがスローされます。同じネットワーク内の他のシステムで同じコードが機能するのは奇妙です。

DEBUG: setDebug: JavaMail version 1.4.5
DEBUG: getProvider() returning     javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc]
DEBUG: mail.imap.fetchsize: 16384
DEBUG: mail.imap.statuscachetimeout: 1000
DEBUG: mail.imap.appendbuffersize: -1
DEBUG: mail.imap.minidletime: 10
DEBUG: trying to connect to host "imap.gmail.com", port 993, isSSL true
javax.mail.MessagingException: sun.security.validator.ValidatorException: PKIX path     building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find     valid certification path to requested target;
  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

どういうわけかこのコードが他のシステムで機能するのは奇妙です。

4

1 に答える 1

-1

メール保護が有効になっているため、ウイルス対策を無効にします。

于 2016-10-27T17:43:17.973 に答える