Spring Integration Mail IMAP-多个接收者

问题描述 投票:0回答:1

我正在使用Spring Boot 2.2.4.RELEASE

我需要构建一个动态邮件接收器,因为我可以有多个邮件服务器来提取邮件。邮件服务器必须可由其他系统配置,因此我的要求是能够动态提取消息。

我进行了调查,我喜欢Spring Integration解决方案及其DSL(请注意:对于我来说,只需下载消息及其附件(如果有)就足够了)。

所以我建立了这段代码:

String flowId = MAIL_IN_FLOW_ID_PREFIX+cpd.getIndirizzoMail();
if( flowContext.getRegistrationById(flowId) != null ) {
    flowContext.remove(flowId);
}
ImapMailInboundChannelAdapterSpec adapterSpec = Mail.imapInboundAdapter(connectionUrl.toString())
    .javaMailProperties(javaMailProperties)
    .shouldDeleteMessages(false)
    .shouldMarkMessagesAsRead(false)
    .selector(selectFunction);
if( confMailIn.isRichiedeAutenticazione() ) {
     adapterSpec = adapterSpec.javaMailAuthenticator(new CasellaPostaleAuthenticator(cpd.getUsername(), cpd.getPassword()));
}

IntegrationFlow flow = IntegrationFlows
.from(adapterSpec.get(), e -> e.poller(Pollers.fixedDelay(Duration.ofSeconds(pollingSeconds)).maxMessagesPerPoll(maxMailMessagePerPoll)))
.handle(message -> {

    logger.info("Message headers "+message.getHeaders());
    logger.info("Message payload "+message.getPayload());
})

.get();

flowContext.registration(flow).id(flowId).register();

我尝试使用我的gmail帐户。该代码可以通过imap连接到GMAIL,但是当我尝试简单地记录消息时,出现此错误:

A6 OK成功

2020-02-05 12:48:41,835 23412 [task-scheduler-1]调试o.s.i.mail.ImapMailReceiver-收到10条消息

2020-02-05 12:48:41,836 23413 [task-scheduler-1] DEBUG oA7 STORE 1+ FLAGS(\ Flagged).s.i.mail.ImapMailReceiver-此邮件服务器不支持USER标志。使用系统标志标记消息

对只读文件夹执行A7 NO STORE尝试(失败)

A8关闭

A8 OK返回到认证状态。 (成功)

DEBUG IMAP:添加了经过身份验证的连接-大小:1

2020-02-05 12:48:42,198 23775 [task-scheduler-1]错误o.s.i.handler.LoggingHandler-org.springframework.messaging.MessagingException:发生故障在轮询邮件时;嵌套异常为javax.mail.MessagingException:对READ-ONLY文件夹进行A7 NO STORE尝试(失败);嵌套的异常是:com.sun.mail.iap.CommandFailedException:尝试执行A7 NO STORE只读文件夹(失败)位于org.springframework.integration.mail.MailReceivingMessageSource.doReceive(MailReceivingMessageSource.java:74)在org.springframework.integration.endpoint.AbstractMessageSource.receive(AbstractMessageSource.java:167)在org.springframework.integration.endpoint.SourcePollingChannelAdapter.receiveMessage(SourcePollingChannelAdapter.java:250)

现在,似乎默认情况下以READ_ONLY方式打开了文件夹,这似乎会导致错误。

我被困在这里,我不知道如何解决这个问题。

有人可以给我小费吗?

谢谢

天使

spring email spring-integration spring-integration-dsl
1个回答
0
投票

adapterSpec.get()

在规范上发布get()规避了Spring的bean初始化逻辑,该逻辑将文件夹切换为读/写。

或者将适配器设置为@Bean,或者简单地将.get()移除。

.from(adapterSpec, e -> ...
© www.soinside.com 2019 - 2024. All rights reserved.