Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to configure dynamic inbound for Spring integration mail?

I am new in spring mail integration, and bellow i put my configuration for mail:inbound-channel-adapter. But i want that the attribute store-uri to be dynamique, and i can update it from my Java controller. Because this attribute is not constante in my context of application.

<int-mail:inbound-channel-adapter id="pop3ShouldDeleteTrue"
                    store-uri="imaps://tata:[email protected]:993/inbox"
                    channel="receiveChannel"
                    should-delete-messages="true"
                    auto-startup="false"
                    java-mail-properties="javaMailProperties">
        <!-- Will poll every 20 seconds -->
        <int:poller fixed-rate="20000"/>
</int-mail:inbound-channel-adapter> 

1 Answers

The URL is a final field in the inbound adapter (actually an ImapMailReceiver component passed into a MailReceivingMessageSource) so it can't be updated.

The only way to change the URL would be to rebuild both classes and inject them into the SourcePollingChannelAdapter that represents the inbound adapter.

However, that won't be thread-safe so I don't think it's safe to do that in a web container.

It's probably easier to simply construct an ImapMailReceiver on-demand and call the receive() method, then use a MessagingTemplate to send the message to a channel.

like image 109
Gary Russell Avatar answered Nov 28 '25 03: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!