Is there any one successfully could add "Disposition-Notification-To" to header using Spring email integration?
I tried two methods
First one is using Spring's application context. In the below XML file, I added header-enricher but din't work. "mydomain.com" is just random domain I added to my local James email server 3.7.1.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/mail http://www.springframework.org/schema/integration/mail/spring-integration-mail.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-mail="http://www.springframework.org/schema/integration/mail"
xmlns:util="http://www.springframework.org/schema/util">
<int:channel id="sendEmailChannel" />
<int:channel id="enrichedEmailChannel" />
<int:channel id="notificationAddedEmailChannel" />
<int:gateway id="emailGateway"
service-interface="mydomain.EmailGateway"
default-request-channel="sendEmailChannel" />
<int:transformer ref="emailInvoiceTransformer"
method="transformEmailMessageToMessage"
input-channel="sendEmailChannel"
output-channel="transformedEmailChannel" />
<int-mail:header-enricher
input-channel="transformedEmailChannel"
output-channel="enrichedEmailChannel">
<int-mail:content-type value="text/html; charset=utf-8" />
</int-mail:header-enricher>
<int:header-enricher
input-channel="enrichedEmailChannel"
output-channel="notificationAddedEmailChannel">
<int:header name="Disposition-Notification-To" value="me@mydomain.com" />
</int:header-enricher>
<int-mail:outbound-channel-adapter
channel="enrichedEmailChannel" host="${mail.host}" port="${mail.port}" />
Another method is using MessageBuilder as below. But still I couldn't find the added header in the generated email.
...
Message<?> message = MessageBuilder.withPayload(payload)
.setHeader("mail_to", emailAddressTo)
.setHeader("mail_from", emailAddressReplyTo)
.setHeader("mail_reply_to" emailAddressReplyTo)
.setHeader("mail_subject", "TEST EMAIL")
.setHeader("Disposition-Notification-To", emailAddressReplyTo)
.build();
return message;
Both methods don't work.
I am using Thunderbird as an email client. I guess the email client doesn't matter here as the expected header doesn't exist anyways.
The MailSendingMessageHandler
does not support custom headers.
We probably can think about doing that via HeaderMapper<MimeMessage>
as we do on the inbound side, but for now you have to go the way creating a MimeMessage
before producing it instead.
See JavaMailSender.createMimeMessage()
API. There you can use the required MimeMessage.setHeader(("Disposition-Notification-To", emailAddressReplyTo)
.