在Spring中与Java配置集成接收邮件

在Spring中与Java配置集成接收邮件,java,spring,spring-integration,dsl,Java,Spring,Spring Integration,Dsl,我想用Spring Integration接收邮件。我已经找到了很多使用xml配置的示例,但没有找到任何使用JavaDSL配置的示例。如何使用JavaDSL编写以下xml配置 <int-mail:inbound-channel-adapter id="imapAdapter" store-uri="imaps://[username]:[password]@imap.gmail.com/INBOX" channel="receiveChannel" sh

我想用Spring Integration接收邮件。我已经找到了很多使用xml配置的示例,但没有找到任何使用JavaDSL配置的示例。如何使用JavaDSL编写以下xml配置

<int-mail:inbound-channel-adapter id="imapAdapter"
      store-uri="imaps://[username]:[password]@imap.gmail.com/INBOX"
      channel="receiveChannel"
      should-delete-messages="true">
      <int:poller max-messages-per-poll="1" fixed-rate="5000"/>
</int-mail:inbound-channel-adapter>

我尝试了以下解决方案,但不知道如何添加轮询器

@Bean
public IntegrationFlow mailListener() {
    return IntegrationFlows.from(Mail.imapInboundAdapter("imaps://[username]:[password]@imap.gmail.com/INBOX").shouldDeleteMessages(true).get())
            .<Message>handle((payload, header) -> logMail(payload))
            .get();
}
@Bean
公共集成流mailListener(){
返回IntegrationFlows.from(Mail.imapInboundAdapter(“imaps://[username]:[password]@imap.gmail.com/INBOX”)。shouldDeleteMessages(true.get())
.handle((有效负载,标题)->日志邮件(有效负载))
.get();
}
请参阅

@Bean
公共集成流mailListener(){
返回IntegrationFlows.from(Mail.imapInboundAdapter(“imaps://[username]:[password]@imap.gmail.com/INBOX”)
.shouldDeleteMessages(true).get(),
e->e.poller(Pollers.fixedRate(5000.maxMessagesPerPoll(1)))
.handle((有效负载,标题)->日志邮件(有效负载))
.get();
}

尝试使用上述代码o.s.integration.handler.LoggingHandler:org.springframework.messaging.MessagingException创建pop3连接时,我遇到以下错误:轮询邮件时出错;嵌套的异常是javax.mail.AuthenticationFailedException:授权失败我的凭据是正确的我仔细检查了一遍。不要对旧答案发表评论;提出一个显示配置的新问题。显然你的证件是错的;很可能您的密码有一些需要转义的特殊字符。请调查一下@gary@GaryRussell你能看一看吗
@Bean
public IntegrationFlow mailListener() {
    return IntegrationFlows.from(Mail.imapInboundAdapter("imaps://[username]:[password]@imap.gmail.com/INBOX")
             .shouldDeleteMessages(true).get(), 
             e -> e.poller(Pollers.fixedRate(5000).maxMessagesPerPoll(1)))
        .<Message>handle((payload, header) -> logMail(payload))
        .get();
}