I am trying to access emails from Gmail accounts through IMAP with the help of the JavaMail API.
I am able to access the Inbox folder of both email accounts. But i want to view only not read message, and the number of it, it is possible ? Thank you in advance.
Here is the code:
  // retrieve the messages from the folder in an array and print it
  Message[] messages = emailFolder.getMessages();
  System.out.println("messages.length---" + messages.length);
  for (int i = 0, n = messages.length; i < n; i++) {
     Message message = messages[i];
     System.out.println("---------------------------------");
     System.out.println("Email Number " + (i + 1));
     System.out.println("Subject: " + message.getSubject());
     System.out.println("From: " + message.getFrom()[0]);
     System.out.println("Text: " + message.getContent().toString());
  }
 
    