java imap从日期开始获取消息 [英] java imap fetch messages since a date

查看:281
本文介绍了java imap从日期开始获取消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用javax.mail包从IMAP文件夹中使用Java来获取电子邮件。我成功地能够检索文件夹中的最后n条消息,但是我正在寻找一个示例来从指定的日期起检索消息。任何例子?

解决方案

您还可以在java邮件包中使用SearchTerm类。

  SearchTerm olderThan = new ReceivedDateTerm(ComparisonTerm.LT,someFutureDate); 
SearchTerm newerThan = new ReceivedDateTerm(ComparisonTerm.GT,somePastDate);
SearchTerm和Term = new AndTerm(olderThan,newerThan);
inbox.search(andTerm);

上述的某些组合应该是在一定范围内获取日期的更好方法。 / p>

I am writing/learning to fetch email using java from an IMAP folder using javax.mail package. I was successfully able to retrieve the last n messages in a Folder, however I am looking to build an example to retrieve messages since a specified date. Any examples?

解决方案

You could also use the SearchTerm classes in the java mail package.

SearchTerm olderThan = new ReceivedDateTerm(ComparisonTerm.LT, someFutureDate);
SearchTerm newerThan = new ReceivedDateTerm(ComparisonTerm.GT, somePastDate);
SearchTerm andTerm = new AndTerm(olderThan, newerThan);
inbox.search(andTerm);

Some combination of the above should prove to be a better way to get dates within a certain range.

这篇关于java imap从日期开始获取消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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