Mail Support
Mail-Sending Channel Adapter
Spring Integration provides support for outbound email with the
MailSendingMessageHandler. It delegates to a configured instance of Spring's
JavaMailSender:
JavaMailSender mailSender = (JavaMailSender) context.getBean("mailSender");
MailSendingMessageHandler mailSendingHandler = new MailSendingMessageHandler(mailSender);
MailSendingMessageHandler various mapping strategies use Spring's
MailMessage abstraction. If the received Message's payload is already
a MailMessage instance, it will be sent directly. Therefore, it is generally recommended to precede this
consumer with a Transformer for non-trivial MailMessage construction requirements. However, a few simple
Message mapping strategies are supported out-of-the-box. For example, if the message payload is a byte array,
then that will be mapped to an attachment. If the payload is neither a MailMessage or byte array, then a
MailMessage will be created with text content corresponding to the value returned from the Spring Integration
Message payload's toString() method. For simple text-based emails, simply provide a
String-based Message payload.
The outbound MailMessage may also be configured with certain values from the
MessageHeaders. If available, values will be mapped to the outbound mail's
properties, such as the recipients (TO, CC, and BCC), the from/reply-to, and the subject. The header names are
defined by the following constants:
MailHeaders.SUBJECT
MailHeaders.TO
MailHeaders.CC
MailHeaders.BCC
MailHeaders.FROM
MailHeaders.REPLY_TO
Mail Namespace Support
Spring Integration provides a namespace for mail-related configuration. To use it, configure the following schema
locations.
]]>
To configure an outbound Channel Adapter, provide the channel to receive from, and the MailSender:
]]>
Alternatively, provide the host, username, and password:
]]>
Keep in mind, as with any outbound Channel Adapter, if the referenced channel is a PollableChannel, a
<poller> sub-element should be provided with either an interval-trigger or cron-trigger.
When using the namespace support, a header-enricher Message Transformer is also available.
This simplifies the application of the headers mentioned above to any Message prior to sending to the
Mail-sending Channel Adapter. Also, note that a boolean value c
]]>