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

时间:2012-01-25 10:57:40

标签: java gmail javamail

props.put("mail.pop3.host", "pop.gmail.com");
        props.put("mail.pop3.user", "xxx@gmail.com");
        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

    }

错误:

  

javax.mail.MessagingException:连接失败;嵌套异常是:java.net.ConnectException:连接超时:连接错误

我在此应用程序中添加了代理设置     并设置防火墙。仍然是它给出了上述错误。