微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Spring Integration Mail 入站复制与 Outlook

如何解决Spring Integration Mail 入站复制与 Outlook

我目前正在开展一个项目,该项目将轮询电子邮件收件箱以获取每日报告。

当点击 Amazon Workmail 上托管的电子邮件用户时,我有一个使用 spring-integration-mail 和 imapInboundAdapter 的工作实现。

当收件箱中有一封未读且未标记的电子邮件时,它会收到该电子邮件并正确地仅发送一封邮件

但是,当我将电子邮件服务器更改为由 Outlook 托管的服务器时,我反而在同一次投票中收到了两次电子邮件

据我所知,电子邮件的可见/标志状态似乎直到 Outlook 中的第二次轮询尝试才会更新,但在工作邮件的第一次尝试时会更新。

对 Outlook 的第二次尝试检索到了一封本应已被处理的电子邮件

IntegrationFlows
    .from(
        Mail.imapInboundAdapter(format("imaps://%s:%s/INBox",source.getHost(),source.getPort()))
            .javaMailAuthenticator(authenticator)
            .maxFetchSize(10),e -> e.poller(... maxMessagesPerPoll = -1,crontrigger = "*/15 * * ? * *" ...)
    ).log(INFO,m -> "Received email: " + m)

这是点击工作邮件时发生的日志记录:

com.sun.mail.imap.connectionpool         : getStoreProtocol() - connection available -- size: 1
com.sun.mail.imap.connectionpool         : getStoreProtocol() -- storeConnectionInUse
com.sun.mail.imap                        : IMAPProtocol noop
com.sun.mail.imap.connectionpool         : releaseStoreProtocol()
com.sun.mail.imap.connectionpool         : getStoreProtocol() borrowing a connection
com.sun.mail.imap.connectionpool         : getStoreProtocol() - connection available -- size: 1
com.sun.mail.imap.connectionpool         : getStoreProtocol() -- storeConnectionInUse
com.sun.mail.imap.connectionpool         : releaseFolderStoreProtocol()
o.s.integration.mail.ImapMailReceiver    : opening folder [imaps://[SNIPPED]@imap.mail.us-west-2.awsapps.com:993/INBox]
com.sun.mail.imap                        : connection available -- size: 1
com.sun.mail.imap.messagecache           : create cache of size 8
o.s.integration.mail.ImapMailReceiver    : attempting to receive mail from folder [INBox]
o.s.integration.mail.ImapMailReceiver    : This email server does not support RECENT or USER flags. System flag 'Flag.FLAGGED' will be used to prevent duplicates during email fetch.
com.sun.mail.imap.messagecache           : create message number 8
o.s.integration.mail.ImapMailReceiver    : found 1 new messages
o.s.integration.mail.ImapMailReceiver    : Received 1 messages
o.s.integration.mail.ImapMailReceiver    : USER flags are not supported by this mail server. Flagging message with system flag
com.sun.mail.imap.connectionpool         : connection pool current size: 0   pool size: 1
com.sun.mail.imap.connectionpool         : connection pool current size: 0   pool size: 1
com.sun.mail.imap                        : added an Authenticated connection -- size: 1
o.s.i.mail.MailReceivingMessageSource    : received mail message [org.springframework.integration.mail.AbstractMailReceiver$IntegrationMimeMessage@a101a27]
o.s.integration.handler.LoggingHandler   : Received email: Genericmessage [payload=org.springframework.integration.mail.AbstractMailReceiver$IntegrationMimeMessage@a101a27,headers={id=20fb1886-eeda-c1e2-7ce0-8a9aae4f7ebc,timestamp=1624590243455}]
com.sun.mail.imap.connectionpool         : getStoreProtocol() - connection available -- size: 1
com.sun.mail.imap.connectionpool         : getStoreProtocol() -- storeConnectionInUse
com.sun.mail.imap                        : IMAPProtocol noop
com.sun.mail.imap.connectionpool         : releaseStoreProtocol()
com.sun.mail.imap.connectionpool         : getStoreProtocol() borrowing a connection
com.sun.mail.imap.connectionpool         : getStoreProtocol() - connection available -- size: 1
com.sun.mail.imap.connectionpool         : getStoreProtocol() -- storeConnectionInUse
com.sun.mail.imap.connectionpool         : releaseFolderStoreProtocol()
o.s.integration.mail.ImapMailReceiver    : opening folder [imaps://[SNIPPED]@imap.mail.us-west-2.awsapps.com:993/INBox]
com.sun.mail.imap                        : connection available -- size: 1
com.sun.mail.imap.messagecache           : create cache of size 8
o.s.integration.mail.ImapMailReceiver    : attempting to receive mail from folder [INBox]
o.s.integration.mail.ImapMailReceiver    : This email server does not support RECENT or USER flags. System flag 'Flag.FLAGGED' will be used to prevent duplicates during email fetch.
o.s.integration.mail.ImapMailReceiver    : found 0 new messages
o.s.integration.mail.ImapMailReceiver    : Received 0 messages
com.sun.mail.imap.connectionpool         : connection pool current size: 0   pool size: 1
com.sun.mail.imap.connectionpool         : connection pool current size: 0   pool size: 1
com.sun.mail.imap                        : added an Authenticated connection -- size: 1

这是点击 Outlook 时发生的日志记录:

com.sun.mail.imap.connectionpool         : getStoreProtocol() - connection available -- size: 1
com.sun.mail.imap.connectionpool         : getStoreProtocol() -- storeConnectionInUse
com.sun.mail.imap                        : IMAPProtocol noop
com.sun.mail.imap.connectionpool         : releaseStoreProtocol()
com.sun.mail.imap.connectionpool         : getStoreProtocol() borrowing a connection
com.sun.mail.imap.connectionpool         : getStoreProtocol() - connection available -- size: 1
com.sun.mail.imap.connectionpool         : getStoreProtocol() -- storeConnectionInUse
com.sun.mail.imap.connectionpool         : releaseFolderStoreProtocol()
o.s.integration.mail.ImapMailReceiver    : opening folder [imaps://[SNIPPED]@outlook.office365.com:993/INBox]
com.sun.mail.imap                        : connection available -- size: 1
com.sun.mail.imap.messagecache           : create cache of size 2
o.s.integration.mail.ImapMailReceiver    : attempting to receive mail from folder [INBox]
o.s.integration.mail.ImapMailReceiver    : This email server does not support RECENT or USER flags. System flag 'Flag.FLAGGED' will be used to prevent duplicates during email fetch.
com.sun.mail.imap.messagecache           : create message number 2
o.s.integration.mail.ImapMailReceiver    : found 1 new messages
o.s.integration.mail.ImapMailReceiver    : Received 1 messages
o.s.integration.mail.ImapMailReceiver    : USER flags are not supported by this mail server. Flagging message with system flag
com.sun.mail.imap.connectionpool         : connection pool current size: 0   pool size: 1
com.sun.mail.imap.connectionpool         : connection pool current size: 0   pool size: 1
com.sun.mail.imap                        : added an Authenticated connection -- size: 1
o.s.i.mail.MailReceivingMessageSource    : received mail message [org.springframework.integration.mail.AbstractMailReceiver$IntegrationMimeMessage@5dffc30b]
o.s.integration.handler.LoggingHandler   : Received email: Genericmessage [payload=org.springframework.integration.mail.AbstractMailReceiver$IntegrationMimeMessage@5dffc30b,headers={id=9d158e52-d46e-fd82-38b7-b438a4899a1e,timestamp=1624589763164}]
com.sun.mail.imap.connectionpool         : getStoreProtocol() - connection available -- size: 1
com.sun.mail.imap.connectionpool         : getStoreProtocol() -- storeConnectionInUse
com.sun.mail.imap                        : IMAPProtocol noop
com.sun.mail.imap.connectionpool         : releaseStoreProtocol()
com.sun.mail.imap.connectionpool         : getStoreProtocol() borrowing a connection
com.sun.mail.imap.connectionpool         : getStoreProtocol() - connection available -- size: 1
com.sun.mail.imap.connectionpool         : getStoreProtocol() -- storeConnectionInUse
com.sun.mail.imap.connectionpool         : releaseFolderStoreProtocol()
o.s.integration.mail.ImapMailReceiver    : opening folder [imaps://[SNIPPED]@outlook.office365.com:993/INBox]
com.sun.mail.imap                        : connection available -- size: 1
com.sun.mail.imap.messagecache           : create cache of size 2
o.s.integration.mail.ImapMailReceiver    : attempting to receive mail from folder [INBox]
o.s.integration.mail.ImapMailReceiver    : This email server does not support RECENT or USER flags. System flag 'Flag.FLAGGED' will be used to prevent duplicates during email fetch.
com.sun.mail.imap.messagecache           : create message number 2
o.s.integration.mail.ImapMailReceiver    : found 1 new messages
o.s.integration.mail.ImapMailReceiver    : Received 1 messages
o.s.integration.mail.ImapMailReceiver    : USER flags are not supported by this mail server. Flagging message with system flag
com.sun.mail.imap.connectionpool         : connection pool current size: 0   pool size: 1
com.sun.mail.imap.connectionpool         : connection pool current size: 0   pool size: 1
com.sun.mail.imap                        : added an Authenticated connection -- size: 1
o.s.i.mail.MailReceivingMessageSource    : received mail message [org.springframework.integration.mail.AbstractMailReceiver$IntegrationMimeMessage@59c04c6c]
o.s.integration.handler.LoggingHandler   : Received email: Genericmessage [payload=org.springframework.integration.mail.AbstractMailReceiver$IntegrationMimeMessage@59c04c6c,headers={id=002e6b83-caf5-86cd-b090-44aa346df119,timestamp=1624589766210}]
com.sun.mail.imap.connectionpool         : getStoreProtocol() - connection available -- size: 1
com.sun.mail.imap.connectionpool         : getStoreProtocol() -- storeConnectionInUse
com.sun.mail.imap                        : IMAPProtocol noop
com.sun.mail.imap.connectionpool         : releaseStoreProtocol()
com.sun.mail.imap.connectionpool         : getStoreProtocol() borrowing a connection
com.sun.mail.imap.connectionpool         : getStoreProtocol() - connection available -- size: 1
com.sun.mail.imap.connectionpool         : getStoreProtocol() -- storeConnectionInUse
com.sun.mail.imap.connectionpool         : releaseFolderStoreProtocol()
o.s.integration.mail.ImapMailReceiver    : opening folder [imaps://[SNIPPED]@outlook.office365.com:993/INBox]
com.sun.mail.imap                        : connection available -- size: 1
com.sun.mail.imap.messagecache           : create cache of size 2
o.s.integration.mail.ImapMailReceiver    : attempting to receive mail from folder [INBox]
o.s.integration.mail.ImapMailReceiver    : This email server does not support RECENT or USER flags. System flag 'Flag.FLAGGED' will be used to prevent duplicates during email fetch.
o.s.integration.mail.ImapMailReceiver    : found 0 new messages
o.s.integration.mail.ImapMailReceiver    : Received 0 messages
com.sun.mail.imap.connectionpool         : connection pool current size: 0   pool size: 1
com.sun.mail.imap.connectionpool         : connection pool current size: 0   pool size: 1
com.sun.mail.imap                        : added an Authenticated connection -- size: 1

解决方法

该问题与 windows Outlook 邮件客户端直接相关。

如果您在 Outlook 客户端中添加带有 imap 的帐户,如果您通过客户端将电子邮件标记为未读(可能与文件夹处理相关),则会导致重复发生。

我不确定确切的原因,但将该帐户添加为完整的 Outlook 帐户(而不是通过 imap)解决了该问题。

否则,您可以在 Web 浏览器而不是 Outlook 客户端中将电子邮件标记为未读。

,

听起来 setFlag() 是 Outlook 的异步。您可以考虑不一次获取所有消息 - .maxFetchSize(1)。另一种方法是使用自定义 SearchTermStrategyselector 跳过您已阅读的消息。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。