This method gives the number of emails in the inbox.But it gives me this exception :
javax.mail.MessagingException: Connect failed;
nested exception is:
java.net.ConnectException: Connection timed out: connecterror
-
Session session = Session.getInstance(new Properties());
try {
Store store = session.getStore("pop3");
store.connect("pop.gmail.com" , "username" , "password");
Folder fldr = store.getFolder("INBOX");
fldr.open(Folder.READ_WRITE);
int count = fldr.getMessageCount();
System.out.println(count);
} catch(Exception exc) {
System.out.println(exc + "error");
}
Probably because the server refuses to connect.
Try connecting from "telnet". Once you can connect at all, then you should be able to connect from your Java program.
Here are some troubleshooting tips: