2012-02-24 125 views
2

在我的应用程序中,我尝试使用java邮件API通过一个邮箱读取收到反弹的电子邮件记录,我相信我们可以使用javax.mail.Message尝试获取给定日期范围的消息

// 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的

回答

1

进行更改后,我没有做这项工作按我的预期:

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) 

干杯! Vaibhav

2

参见Folder.search()方法和在javax.mail.search包中的许多搜索项。

请注意,IMAP搜索是在服务器上完成的,但只有分辨率为几天而不是时间。 POP3搜索是通过下载所有消息到客户端并在那里搜索完成的;可能不是你想要做的。

+0

感谢这工作! – vaibhav 2012-02-29 05:34:52