javax.mail Office365 读取和 ComparisonTerm 问题
javax.mail over Office365 read and ComparisonTerm issues
我很简单地尝试阅读收件箱中的所有邮件,然后分类为已读、未读和大于或等于日期条款。请在下面查看我的代码。用户名和密码部分已通过。
通常代码很简单,但我不明白为什么我只收到所有电子邮件。
同时,我确定阅读消息。电子邮件的接收日期也不同,我们有新的电子邮件。
没有异常或错误。
还检查了下面的内容以及其他几个问题。
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
接收日期期限:0
谢谢
如 javadocs for the com.sun.mail.pop3 package 中所述,POP3 协议不支持永久标记,因此无法判断邮件是最近的还是已看到的。请改用 imap。
此外,您需要修复这些 common JavaMail mistakes。
我很简单地尝试阅读收件箱中的所有邮件,然后分类为已读、未读和大于或等于日期条款。请在下面查看我的代码。用户名和密码部分已通过。
通常代码很简单,但我不明白为什么我只收到所有电子邮件。
同时,我确定阅读消息。电子邮件的接收日期也不同,我们有新的电子邮件。
没有异常或错误。
还检查了下面的内容以及其他几个问题。
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 接收日期期限:0
谢谢
如 javadocs for the com.sun.mail.pop3 package 中所述,POP3 协议不支持永久标记,因此无法判断邮件是最近的还是已看到的。请改用 imap。
此外,您需要修复这些 common JavaMail mistakes。