Read all emails from inbox after a specified date and time in java using javax.mail -
right able read unread emails messages using java need read emails after specified date , time using javax.mail (ie javax.mail.jar), please me in retrieving emails using java after specified date , time (say 12 july 2013,1pm). code reading mails :
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");
here 1 example taken javax.mail.message trying fetch messages given date range
cal.add(calendar.day_of_month, -1); // bounce mails received yesterday receiveddateterm term = new receiveddateterm(comparisonterm.eq,newdate(cal.gettimeinmillis())); message[] messages = folder.search(term)
another approach of using term be:
searchterm olderthan = new receiveddateterm(comparisonterm.lt, somefuturedate); searchterm newerthan = new receiveddateterm(comparisonterm.gt, somepastdate); searchterm andterm = new andterm(olderthan, newerthan); inbox.search(andterm);
Comments
Post a Comment