2

I would like to poll emails based on subject.

If we would like to poll emails which has the Subject as "Test”, the below code fetches all the emails. But we need to filter the ones with subject "Test".

How can I filter based on subject?

@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();
    }
}

I am using pop3Channel and tried by using filter. However not sure how to get to the solution.

Community
  • 1
  • 1
Ethan
  • 21
  • 4

1 Answers1

0

I know this is very old question, answering this as it can be helpful to anyone having same requirement.

Use 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();
}
samabcde
  • 6,988
  • 2
  • 25
  • 41
Mujahid
  • 127
  • 1
  • 2
  • 10