-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand Mail documentation with DSL examples #10572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
The Mail module documentation previously only showed XML configuration examples. This update adds examples for Java, Java DSL, Kotlin DSL, and Groovy DSL to help developers using these different configuration styles. Changes include: - Outbound channel adapter configuration in all DSL flavors - Header enricher examples for all supported languages - Inbound adapters (both polling and IDLE) with DSL examples - JavaMail properties configuration examples - Search term strategy configuration examples - Mail filter expression examples across all DSL types - Transaction synchronization examples for all configurations - Minor typo fix in SearchTerm documentation - Minor grammar fixes This makes the documentation more accessible to developers who prefer annotation-based or DSL configuration over XML. Note: In some cases there is no DSL for java, kotlin, or groovy. This is because the sample is for a supporting bean of the DSL vs. the DSL itself.
artembilan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is right direction.
Thank for such a thorough rework!
Sorry for a lengthy review.
| return new MailToStringTransformer(); | ||
| } | ||
| ... | ||
| .transform(Mail.toStringTransformer()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just minor: there is no need in period for Kotlin/Groovy DSLs.
See examples in the KotlinDslTests and GroovyDslTests, respectively.
😄
| @ServiceActivator(inputChannel = "outboundMail") | ||
| public MessageHandler outboundMailMessageHandler(JavaMailSender mailSender) { | ||
| MailSendingMessageHandler handler = new MailSendingMessageHandler(mailSender); | ||
| return handler; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit-pick: no need in local variable if we don't use it.
Just return new MailSendingMessageHandler(mailSender)`.
| fun mailOutboundFlow(mailSender: JavaMailSender): IntegrationFlow { | ||
| return IntegrationFlow.from("outboundMail") | ||
| .handle(Mail.outboundAdapter(mailSender)) | ||
| .get() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not Kotlin idiomatic style.
Let me know if you'd like to pair on these samples!
Neither Groovy bellow.
| [[configuring-outbound-channel-adapters]] | ||
| == Configuring Outbound Channel Adapters | ||
|
|
||
| To configure an outbound channel adapter, provide the channel from which to receive and the MailSender, as the following example shows: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The MailSender must be a code snippet.
| ====== | ||
|
|
||
| Alternatively, you can provide the host, username, and password, as the following example shows: | ||
| Alternatively, you can configure the mail sender directly with host credentials: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, this is a bit confusing.
Samples above show a JavaMailSender injection, but is there its definition?
| fun imapMailReceiver(): ImapMailReceiver { | ||
| return ImapMailReceiver("imap:something").apply { | ||
| // ... | ||
| setSearchTermStrategy(TestSearchTermStrategy()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an instantiation of the TestSearchTermStrategy directly.
While all other samples talk about an injection into bean method.
| Spring Integration 2.0.4 introduced the `mail-filter-expression` attribute on `inbound-channel-adapter` and `imap-idle-channel-adapter`. | ||
| This attribute lets you provide an expression that is a combination of SpEL and a regular expression. | ||
| For example, if you would like to read-only emails that contain 'Spring Integration' in the subject line, you would configure the `mail-filter-expression` attribute like as follows: `mail-filter-expression="subject matches '(?i).\*Spring Integration.*"`. | ||
| For example, if you would like to read only emails that contain 'Spring Integration' in the subject line, you would configure the `mail-filter-expression` attribute like as follows: `mail-filter-expression="subject matches '(?i).\*Spring Integration.*"`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is correct fix.
read only and read-only have a different meaning and reads differently.
| You can enable transaction synchronization by adding a `<transactional/>` element to the poller for the polled `<inbound-adapter/>` or to the `<imap-idle-inbound-adapter/>`. | ||
| When using XML schema, transaction synchronization is enabled by adding a `<transactional/>` element to the poller for the polled `<inbound-adapter/>` or to the `<imap-idle-inbound-adapter/>`. | ||
| Even if there is no 'real' transaction involved, you can still enable this feature by using a `PseudoTransactionManager` with the `<transactional/>` element. | ||
| When using Java configuration you can establish the transaction synchronization by using the `transactionSynchronizationFactory(transactionSynchronizationFactory)` method on the `PollerMetadata` or via the DSL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a comma is supposed to be after the first part of the sentence when it starts with when, if, because.
My English is not the best, but still some rules are in my head 😄
| ---- | ||
| @Bean | ||
| public IntegrationFlow imapIdleFlow(ImapMailReceiver imapMailReceiver, MessageChannel receiveChannel, | ||
| MailMessageHandler mailMessageHandler) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no such a class in the Framework.
And I don't think we need to mention anything here at all.
See XML sample this was derived from.
| ) | ||
| } | ||
| return IntegrationFlow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kotlin DSL sample needs more work.
And ExpressionEvaluatingTransactionSynchronizationProcessor has to be a bean.
The Mail module documentation previously only showed XML configuration examples. This update adds examples for Java, Java DSL, Kotlin DSL, and Groovy DSL to help developers using these different configuration styles.
Changes include:
This makes the documentation more accessible to developers who prefer annotation-based or DSL configuration over XML.
Note:
In some cases there is no DSL for java, kotlin, or groovy. This is because the sample is for a supporting bean of the DSL vs. the DSL itself.