使用 Spring 集成 5.5.12 和 James 电子邮件服务器 3.7.1 添加“Disposition-Notification-To”

问题描述 投票:0回答:1

是否有人可以使用 Spring 电子邮件集成成功地将“Disposition-Notification-To”添加到标头?

我尝试了两种方法

第一个是使用 Spring 的应用程序上下文。 在下面的 XML 文件中,我添加了 header-enricher 但不起作用。 “mydomain.com”只是我添加到本地 James 电子邮件服务器 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="[email protected]" />
</int:header-enricher>

<int-mail:outbound-channel-adapter
    channel="enrichedEmailChannel" host="${mail.host}" port="${mail.port}" />

另一种方法是使用 MessageBuilder,如下所示。 但我仍然无法在生成的电子邮件中找到添加的标头。

        ...
     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;

这两种方法都不起作用。

我使用 Thunderbird 作为电子邮件客户端。我想电子邮件客户端在这里并不重要,因为无论如何预期的标头都不存在。

spring-integration james spring-integration-mail
1个回答
0
投票

MailSendingMessageHandler
不支持自定义标头。

我们可能可以考虑通过

HeaderMapper<MimeMessage>
来完成此操作,就像我们在入站方面所做的那样,但现在您必须先创建
MimeMessage
,然后再生成它。

请参阅

 JavaMailSender.createMimeMessage()
API。在那里您可以使用所需的
MimeMessage.setHeader(("Disposition-Notification-To", emailAddressReplyTo)

© www.soinside.com 2019 - 2024. All rights reserved.