有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

javajavax。Office365上的邮件读取和比较界面问题

我只是尝试阅读收件箱中的所有邮件,然后分类为已读、未读和更大或相等的日期。请看下面我的代码。用户名和密码部分已通过

通常代码很简单,但我不明白为什么我只收到所有的电子邮件

同时,我肯定会阅读信息。此外,电子邮件接收日期不同,我们有新的电子邮件

我没有任何例外或错误

也检查了下面和几个问题

Read Recent and Unseen message using javax.mail


    Properties props = new Properties();
    props.put("mail.host", "outlook.office365.com");
    props.put("mail.store.protocol", "pop3s");
    props.put("mail.pop3s.auth", "true");
    props.put("mail.pop3s.port", "995");

    Session session = Session.getInstance(props, new avax.mail.Authenticator() {
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(username, passwd);
        }
    });

    Security.setProperty("ssl.SocketFactory.provider", "com.ibm.jsse2.SSLSocketFactoryImpl");
    //Security.setProperty("ssl.ServerSocketFactory.provider", "com.ibm.jsse2.SSLServerSocketFactoryImpl");

    Store store = session.getStore("pop3s");
    store.connect();
    Folder emailFolder = store.getFolder("INBOX");
    emailFolder.open(Folder.READ_ONLY);

    Calendar myCal = new GregorianCalendar();
    myCal.setTime(new Date());
    myCal.add(Calendar.DAY_OF_MONTH, -1);

    // retrieve the messages from the folder in an array and print it
    Message[] messages = emailFolder.getMessages();
    System.out.println("ALL : " + messages.length);

    messages =  emailFolder.search(new FlagTerm(new Flags(Flags.Flag.SEEN), false));
    //messages =  emailFolder.search(new FlagTerm(new Flags(Flag.SEEN), false));    // not working also
    System.out.println("UNREAD : " + messages.length);

    messages =  emailFolder.search(new FlagTerm(new Flags(Flags.Flag.SEEN), true));
    //messages =  emailFolder.search(new FlagTerm(new Flags(Flag.SEEN), true));     // not working also

    System.out.println("READ : " + messages.length);

    messages =  emailFolder.search(new ReceivedDateTerm(ComparisonTerm.GE, myCal.getTime()));
    System.out.println("ReceivedDateTerm : " + messages.length);

结果是; 全部:18 未读:18 阅读:0 ReceivedDateTerm:0

谢谢


共 (1) 个答案