【问题标题】:How to filter emails based on subject while polling in Spring Integration如何在 Spring Integration 中轮询时根据主题过滤电子邮件
【发布时间】:2018-03-02 02:32:30
【问题描述】:

我想根据主题对电子邮件进行投票。

如果我们想查询主题为“Test”的邮件,下面的代码会获取所有邮件。但我们需要过滤主题为“Test”的邮件。

如何根据主题进行过滤?

@Configuration
@EnableIntegration
public class PollSubjectEmail {
    @Bean
    public IntegrationFlow pop3MailFlow() {

        return IntegrationFlows
                .from(Mail.pop3InboundAdapter(“xxx.host.com", pop3Port, “username”, “password”)
                        .javaMailProperties(p -> p.put("mail.debug", "true")),
                        e -> e.autoStartup(true).poller(Pollers.fixedDelay(6000)))
                .enrichHeaders(s -> s.headerExpressions(h -> h.put(MailHeaders.SUBJECT, "payload.subject")
                        .put(MailHeaders.FROM, "payload.from[0].toString()")))
                .channel("pop3Channel").get();
    }
}

我正在使用 pop3Channel 并尝试使用过滤器。但是不确定如何找到解决方案。

【问题讨论】:

    标签: java spring jakarta-mail spring-messaging spring-integration-dsl


    【解决方案1】:

    我知道这是一个非常古老的问题,回答这个问题对任何有相同要求的人都有帮助。

    使用MailInboundChannelAdapterSpec#selectorExpression("some expression goes here")

    @Bean
    public IntegrationFlow pop3MailFlow() {
    
        return IntegrationFlows
                .from(Mail.pop3InboundAdapter("xxx.host.com", pop3Port, “username”, “password”)
                        .javaMailProperties(p -> p.put("mail.debug", "true")
                         /* Add the expression as below*/
                        .selectorExpression("subject matches '(?i).*Test.*'")),
                        e -> e.autoStartup(true).poller(Pollers.fixedDelay(6000)))
                .enrichHeaders(s -> s.headerExpressions(h -> h.put(MailHeaders.SUBJECT, "payload.subject")
                        .put(MailHeaders.FROM, "payload.from[0].toString()")))
                .channel("pop3Channel").get();
    }
    

    【讨论】:

      猜你喜欢
      • 2012-12-15
      • 2018-04-29
      • 1970-01-01
      • 2015-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-10
      • 1970-01-01
      相关资源
      最近更新 更多