如何通过 javamail api 查看我的 hotmail 帐户中有多少条未读邮件?

how to check how many unread message I have in my hotmail account by javamail api?

我正在尝试从我的 hotamil 帐户中获取未读消息数。我使用但我有一个问题它总是 return 我收件箱中所有现有的电子邮件号码。在这里我分享我的代码:

public class testEmail {
    public static void check(String host, String storeType, String user,
              String password) 

           {
              try {

              //create properties field
              Properties properties = new Properties();
              properties.put("mail.pop3.host", host);
              properties.put("mail.pop3.port", "995");
             properties.put("mail.pop3.starttls.enable", "true");

             // properties.put("mail.imap.ssl.enable", "true");           
              Session emailSession = Session.getInstance(properties, null);
              emailSession.setDebug(false);

              //create the POP3 store object and connect with the pop server
              Store store = emailSession.getStore("pop3s");

              store.connect(host, user, password);
              //create the folder object and open it
              Folder emailFolder = store.getFolder("INBOX");
              emailFolder.open(Folder.READ_ONLY);

             //for count the unread email 
          FlagTerm ft = new FlagTerm(new Flags(Flags.Flag.SEEN), false);
          Message messages[] = emailFolder.search(ft);
          System.out.println("No. of Unread Messages : " + messages.length);

              emailFolder.close(false);
              store.close();

              } catch (NoSuchProviderException e) {
                 e.printStackTrace();
              } catch (MessagingException e) {
                 e.printStackTrace();
              } catch (Exception e) {
                 e.printStackTrace();
              }
           }

           public static void main(String[] args) {

              String host = "pop-mail.outlook.com";// change accordingly
              String mailStoreType = "pop3";
              String username = "abc@hotmail.com";// change accordingly
              String password = "abc";// change accordingly

              check(host, mailStoreType, username, password);

           }

        }

如果我使用 FlagTerm(new Flags(Flags.Flag.SEEN), true);它的 return 0。这个问题是关于代码还是 Hotmail 帐户。提前致谢。

Flags.Flag.SEEN 在 POP3 中无法正常工作,所以我将其更改为 IMAP。还有一件事,如果 mail.imap.port = 993 不起作用,则使用 25。答案是关于 hotmail 的。