在Spring中接收邮件与Java配置集成
问题描述:
我想收到Spring Integration的邮件。我发现了很多xml配置的例子,但是我还没有发现任何与Java DSL配置有关的例子。如何使用Java DSL编写以下xml配置?在Spring中接收邮件与Java配置集成
<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
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();
}