阅读背景:

无法使用POP API从java代码中读取Gmail INBOX ..给出错误java.net.ConnectException:连接超时:连接错误

来源:互联网 
props.put("mail.pop3.host", "pop.gmail.com");
        props.put("mail.pop3.user", "[email protected]");
        props.put("mail.pop3.socketFactory", 995);
        props.put("mail.pop3.socketFactory.class",
                "javax.net.ssl.SSLSocketFactory");
        props.put("mail.pop3.port", 995);
        Session session = Session.getDefaultInstance(props,
                new Authenticator() {
                    @Override
                    protected PasswordAuthentication getPasswordAuthentication() {
                        return new PasswordAuthentication("xxx",
                                "xxx");
                    }
                });
        try {
            Store store = session.getStore("pop3");
            store.connect("pop.gmail.com", "xxxxx", "xxx");
            Folder fldr = store.getFolder("INBOX");
            fldr.open(Folder.HOLDS_MESSAGES);
            int count = fldr.getMessageCount();
            System.out.println(count);
        } catch (Exception exc) {
            System.out.println(exc + " error");
        }
        // TODO Auto-generated method stub

    }
props.put("mail.pop3.host", "pop.gmail.com");
 



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: