0

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

在访问托管在 Amazon Workmail 上的电子邮件用户时,我有一个使用带有 imapInboundAdapter 的 spring-integration-mail 的工作实现。

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

但是,当我将电子邮件服务器更改为由 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
4

2 回答 2

1

事实证明,该问题与 Windows Outlook 邮件客户端直接相关。

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

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

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

于 2021-06-30T02:38:19.873 回答
0

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

于 2021-06-25T14:34:27.793 回答