title: How to read the UNREAD email using java mail api
body: <p>I am trying to read the UNREAD mails from gmail account. I tried to filter the messages based on the Flags, but it did not work. I printed the Flags sent on each message, but nothing is set on it, because of which I could not filter the messages. I used the keyword Flags.Flag.SEEN to filter the messages. 
  After googling, I found out that it is something with the email client. For ex, we need to the change the configuration in gmail or any exchange mail server. Can you please tell me on what to change the configuration to read the UNREAD mails?</p>
  
  <p>Also, end of day, I am going to implement the code into one of the smtp exchange servers. Please let me know if there needs a special configuration. So that I can inform the respective team and then implement my change.</p>
  
  <pre><code>       // connects to the message store
          Store store = session.getStore("pop3");
          store.connect(userName, password);
  
          // opens the inbox folder
          Folder folderInbox = store.getFolder("INBOX");
          System.out.println("unread count - " + folderInbox.getUnreadMessageCount());
          folderInbox.open(Folder.READ_WRITE);
          // folderInbox.search(new FlagTerm(new Flags(Flags.Flag.RECENT),
          // false));
  
          // fetches new messages from server
          Message[] arrayMessages = folderInbox.search(new FlagTerm(new Flags(Flags.Flag.RECENT), false));
  </code></pre>