0

事实上,我正在尝试通过 Gmail POP3 接收电子邮件,我在 gmail 中启用了 POP3 协议,但通过 SSL 建立了会话和连接,但我是一个例外,无法弄清楚背后的实际问题是什么。这是例外

Exception in thread "main" javax.mail.AuthenticationFailedException: failed to connect
    at javax.mail.Service.connect(Service.java:382)
    at javax.mail.Service.connect(Service.java:226)
    at javax.mail.Service.connect(Service.java:246)
    at EmailReciever.getEmail(EmailReciever.java:47)
    at TestEmailReceiver.main(TestEmailReceiver.java:14)

我把它连接起来

public void getEmail(String host, String port, final String userName, final String password)
            throws MessagingException, IOException {
        // sets POP3 properties
        Properties properties = new Properties();
        properties.put("mail.pop3.com", host);
        properties.put("mail.pop3.port", port);
        properties.put("mail.pop3.auth", "true");
        // sets POP3S properties
        properties.setProperty("mail.pop3.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
        properties.setProperty("mail.pop3.socketFactory.fallback", "false");      
        properties.setProperty("mail.pop3.socketFactory.port", "995");
        Session session = Session.getInstance(properties,
              new javax.mail.Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(userName, password);
                }
                });

请帮忙!

这是我的调试输出...

DEBUG: setDebug: JavaMail version 1.5.0
DEBUG: getProvider() returning javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle]
DEBUG POP3: mail.pop3.rsetbeforequit: false
DEBUG POP3: mail.pop3.disabletop: false
DEBUG POP3: mail.pop3.forgettopheaders: false
DEBUG POP3: mail.pop3.cachewriteto: false
DEBUG POP3: mail.pop3.filecache.enable: false
DEBUG POP3: mail.pop3.keepmessagecontent: false
DEBUG POP3: mail.pop3.starttls.enable: false
DEBUG POP3: mail.pop3.starttls.required: false
4

0 回答 0