如何捕获 ImapMailReceiver 中出现的 AuthenticationFailedException

How to catch AuthenticationFailedException that appeared in ImapMailReceiver

private IntegrationFlowRegistration getIntegrationFlowRegistration(){
  IntegrationFlow flow = IntegrationFlows
            .from(Mail.imapIdleAdapter(createImapMailReceiver(imapUrl))
                    .autoStartup(true)
            )
            .handle(System.out::println)
            .get();
    return this.flowContext.registration(flow).register();

}

我为不同的客户动态创建 IntegrationFlowRegistration,有时凭据不正确。我想捕获 AuthenticationFailedException 并将其记录下来,但找不到捕获它的方法。你能给我一个提示,说明它是怎么做不到的吗?我阅读了 DSL 文档,但没有找到方法或好的示例。

添加一个 ApplicationListener<ImapIdleExceptionEvent> bean,或一个接收该事件类型的 @EventListener 方法。

@EventListener
public void imap(ImapIdleExceptionEvent event) {
...
}

https://docs.spring.io/spring-integration/docs/current/reference/html/mail.html#imap-idle-and-lost-connections

Beginning with the 3.0 release, the IMAP idle adapter emits application events (specifically ImapIdleExceptionEvent instances) when exceptions occur. This allows applications to detect and act on those exceptions. You can obtain the events by using an <int-event:inbound-channel-adapter> or any ApplicationListener configured to receive an ImapIdleExceptionEvent or one of its super classes.