I am trying to write a simple java program which returns me all the unread email from my hotmail account using javamail api. This is the code I am using :
String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
Properties props = new Properties();
props.setProperty("mail.pop3.ssl.enable", "true");
props.setProperty("mail.pop3s.socketFactory.class", SSL_FACTORY);
props.setProperty("mail.pop3s.socketFactory.fallback", "false");
props.setProperty("mail.pop3s.port", "995");
props.setProperty("mail.pop3s.socketFactory.port", "995");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
Store store = session.getStore("pop3");
store.connect("pop3.live.com", username, password);
System.out.println(store);
Folder inbox = store.getFolder("Inbox");
inbox.open(Folder.READ_ONLY);
FlagTerm ft = new FlagTerm(new Flags(Flags.Flag.SEEN), false);
Message messages[] = inbox.search(ft);
What is my mistake in this code? Because I am getting all the mails instead of just the unread ones.