2012-02-24 121 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