java - 使用 spring 集成 IMAP 适配器,如何手动获取标记为 "unread"的电子邮件?

标签 java spring email imap spring-integration

我有一段代码使用 spring integration 的 IMAP 适配器轮询收件箱以读取所有未读的传入电子邮件,并且效果很好。但是,如果我打开任何电子邮件,然后在我的 Outlook 收件箱中将其标记为“未读”,则轮询器不会获取标记的电子邮件。 我可以使用 pop3 适配器来获取所有电子邮件,但之后会删除它们,但我想将电子邮件保留在我的收件箱中,并且我希望轮询器获取所有看不见的电子邮件。

有什么处理这个问题的建议吗?我一直在搜索和阅读有关电子邮件适配器的文章,但没有找到任何有用的信息。

提前致谢。

最佳答案

看来您需要自定义“搜索词策略”。来自 Spring Integration (SI) 文档:

By default, the ImapMailReceiver will search for Messages based on the default SearchTerm which is All mails that are RECENT (if supported), that are NOT ANSWERED, that are NOT DELETED, that are NOT SEEN and have not been processed by this mail receiver (enabled by the use of the custom USER flag or simply NOT FLAGGED if not supported). Since version 2.2, the SearchTerm used by the ImapMailReceiver is fully configurable via the SearchTermStrategy which you can inject via the search-term-strategy attribute. SearchTermStrategy is a simple strategy interface with a single method that allows you to create an instance of the SearchTerm that will be used by the ImapMailReceiver.

这是来自 SI 论坛的帖子,其中包含有趣的 Oleg 解释:Server does not support RECENT or USER flags

在这里你可以找到 SI DefaultSearchTermStrategy :这是一个确定您应该如何实现自己的策略的地方。我想,你的情况是:

This email server does not support RECENT flag, but it does support USER flags which will be used to prevent duplicates during email fetch.

将 SI-mail 日志记录级别切换为 DEBUG 并查看哪个标志支持您的电子邮件服务器。

关于java - 使用 spring 集成 IMAP 适配器,如何手动获取标记为 "unread"的电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18690596/

相关文章:

java - 递归和数组

php - 如何使用 PHP 过滤/删除 Google 电子邮件别名?

PHP获取imap附件的文件大小

java - 不支持使用 JDK 版本 `11.0.1` 构建。请安装 JDK 版本 `1.8.0`

java - 更新嵌套控件内的 PrimeFaces 数据表?

spring - Intellij 中的 Gradle 问题

java - 在什么情况下,返回响应比编辑 HttpServletResponse 更好?

spring - 什么是 OncePerRequestFilter?

java - 邮件发送错误 - SMTPAddressFailedException

java - Java 中将 dropwizard 初始未授权消息自定义为 json 格式