javax.mail.Message试图在给定的日期范围内获取邮件 [英] javax.mail.Message trying to fetch messages for a given date range

查看:1559
本文介绍了javax.mail.Message试图在给定的日期范围内获取邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我尝试使用java邮件API读取一个邮箱,我们收到反弹的电子邮件记录,我相信我们可以使用

  //获取实现指定协议的Store对象。 
store = session.getStore(protocol);
//使用指定的用户名和密码连接到当前的主机。
store.connect(hostName,userName,password);
folder = store.getFolder(folderName);
消息[] messages = folder.getMessages();

但是,这将返回我提供的文件夹中的所有消息,是否有一种方式,在我可以找出我在昨天收到的消息在给定的日期范围。



在这方面的任何帮助将非常感谢。



谢谢



Vaibhav

解决方案

没有按照我的期望做这个工作:

  cal.add(Calendar.DAY_OF_MONTH,-1); 

//我们将收到昨天收到的退回邮件

ReceivedDateTerm term = new ReceivedDateTerm(ComparisonTerm.EQ,newDate(cal.getTimeInMillis()));

消息[] messages = folder.search(term)

干杯!
Vaibhav


In my application i am trying to use java mail API to read through one mailbox where we recieve bounced email records, i believe we can fetch all the messages using

// 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();

However this would return me all the messages in the provided folder, Is there a way where in i can find out the messages which i received yesterday on in a given date range.

Any help in this regard would be highly appreciated.

Thanks

Vaibhav

解决方案

Following changes i did to make this work as per my expectations:

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)

Cheers! Vaibhav

这篇关于javax.mail.Message试图在给定的日期范围内获取邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆