Spring Integration currently provides support for outbound email only with the
MailTarget
. This adapter delegates to a configured instance of Spring's
JavaMailSender
, and its various mapping strategies use Spring's
MailMessage
abstraction. By default text-based mails are created when
the handled message has a String-based payload. If the message payload is a byte array, then that will
be mapped to an attachment.
The adapter also delegates to a MailHeaderGenerator
for providing the
mail's properties, such as the recipients (TO, CC, and BCC), the from/reply-to, and the subject.
public interface MailHeaderGenerator { void populateMailMessageHeader(MailMessage mailMessage, Message<?> message); }
The default implementation will look for attributes in the MessageHeader
with
the following constants defining the keys:
MailAttributeKeys.SUBJECT MailAttributeKeys.TO MailAttributeKeys.CC MailAttributeKeys.BCC MailAttributeKeys.FROM MailAttributeKeys.REPLY_TO
A static implementation is also available out-of-the-box and may be useful for testing. However, when customizing, the properties would typically be generated dynamically based on the message itself. The following is an example of a configured mail adapter.
<bean id="mailTargetAdapter" class="org.springframework.integration.adapter.mail.MailTargetAdapter"> <property name="mailSender" ref="javaMailSender"/> <property name="headerGenerator" ref="dynamicMailMessageHeaderGenerator"/> </bean>