Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fetch all sent mail from imap adaptor spring integration

I need to fetch all sent mail that are not deleted but not happening, but only shows total mails, recent at console in mail.debug true

<int:channel id="receiveChannel" />
    <int-mail:imap-idle-channel-adapter id="customAdapter" 
            store-uri="imaps://[email protected]:[email protected]:993/INBOX.Sent"
            channel="receiveChannel"
            auto-startup="true"
            should-delete-messages="false"
            should-mark-messages-as-read="false"
            java-mail-properties="javaMailProperties"/>

<util:properties id="javaMailProperties">
    <prop key="mail.imap.socketFactory.class">javax.net.ssl.SSLSocketFactory</prop>
    <prop key="mail.imap.socketFactory.fallback">false</prop>
    <prop key="mail.store.protocol">imaps</prop>
    <prop key="mail.debug">true</prop>
</util:properties>




   public static void main (String[] args) throws Exception {

            ApplicationContext ac = new ClassPathXmlApplicationContext("spring/gmail-imap-idle-config.xml");
            DirectChannel inputChannel = ac.getBean("receiveChannel", DirectChannel.class);
            inputChannel.subscribe(new MessageHandler() {
                public void handleMessage(Message<?> message) throws MessagingException {

                    MimeMessage mimeMessage = (MimeMessage) message.getPayload();



    }
});
}
like image 209
rupak Avatar asked Nov 26 '25 08:11

rupak


1 Answers

See the documentation, you need to use a custom SearchTermStrategy.

By default, the ImapMailReceiver will search for Messages based on the default SearchTerm which is All mails that are RECENT (if supported), that are NOT ANSWERED, that are NOT DELETED, that are NOT SEEN and have not been processed by this mail receiver (enabled by the use of the custom USER flag or simply NOT FLAGGED if not supported). The custom user flag is spring-integration-mail-adapter but can be configured. Since version 2.2, the SearchTerm used by the ImapMailReceiver is fully configurable via the SearchTermStrategy which you can inject via the search-term-strategy attribute. SearchTermStrategy is a simple strategy interface with a single method that allows you to create an instance of the SearchTerm that will be used by the ImapMailReceiver.

like image 194
Gary Russell Avatar answered Nov 28 '25 16:11

Gary Russell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!