javax.mail.Message正在尝试获取给定日期范围内的邮件
在我的应用程序中,我尝试使用java mail API来读取一个邮箱,在那里我们接收到被退回的电子邮件记录,我相信我们可以使用javax.mail.Message正在尝试获取给定日期范围内的邮件,java,date,jakarta-mail,Java,Date,Jakarta Mail,在我的应用程序中,我尝试使用java mail 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(h
// 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查看Folder.search()方法和javax.mail.search包中的许多搜索词
请注意,IMAP搜索是在服务器上完成的,但只能解析为天,而不能解析为时间。
POP3搜索通过将所有消息下载到客户端并在那里搜索来完成;可能不是你想做的。我做了以下更改,使这项工作符合我的期望:
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)
干杯!
维巴夫