现在我可以使用java读取所有未读电子邮件消息,但我需要使用JAVAX.Mail(即javax.mail.jar)在指定日期和时间之后阅读所有电子邮件,请帮我检索所有电子邮件在指定的日期和时间之后使用java(比如说2013年7月12日下午1点)。 我的阅读邮件代码:
Properties prop = System.getProperties();
prop.getProperty("mail.store.protocol", "imaps");
Session session = Session.getDefaultInstance(prop, null);
Store store = session.getStore("imaps");
store.connect("imap.gmail.com", "myGmailId@gmail.com", "mypassword");
inbox = store.getFolder("Inbox");
答案 0 :(得分:2)
以下是javax.mail.Message trying to fetch messages for a given date range
的一个示例cal.add(Calendar.DAY_OF_MONTH, -1);
// We would get the bounce mails received yesterday
ReceivedDateTerm term = new ReceivedDateTerm(ComparisonTerm.EQ,newDate(cal.getTimeInMillis()));
Message[] messages = folder.search(term)
使用术语的另一种方法可能是:
SearchTerm olderThan = new ReceivedDateTerm(ComparisonTerm.LT, someFutureDate);
SearchTerm newerThan = new ReceivedDateTerm(ComparisonTerm.GT, somePastDate);
SearchTerm andTerm = new AndTerm(olderThan, newerThan);
inbox.search(andTerm);