在我的应用程序中,我试图使用java邮件API来读取一个邮箱,在该邮箱中我们接收退回的电子邮件记录,我相信我们可以使用以下方式来获取所有消息:
// Get a Store object that implements the specified protocol.
store = session.getStore(protocol);
//Connect to the current host using the specified username and password.
store.connect(hostName, userName, password);
folder = store.getFolder(folderName);
Message[] messages = folder.getMessages();
但是这将返回给我提供的文件夹中的所有消息,有没有一种方法可以让我找出给定日期范围内昨天收到的消息。
在这方面的任何帮助将不胜感激。
谢谢
Vaibhav
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DAY_OF_MONTH, -1);
// We would get the bounce mails received yesterday
ReceivedDateTerm term = new ReceivedDateTerm(ComparisonTerm.EQ,new Date(cal.getTimeInMillis()));
Message[] messages = folder.search(term)