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:连接超时:连接错误
我在此应用程序中添加了代理设置 并设置防火墙。仍然是它给出了上述错误。
答案 0 :(得分:0)