JavaMail - 标题顺序

时间:2015-04-30 11:01:35

标签: java javamail

我遇到了一些问题,因为我的邮件标题出了故障。可以保持我添加itens的顺序吗?我希望我的所有自定义标题信息都在标题“Return-Path”之前。

我已经读过关于方法addHeader(key,value)和类似反向的东西,但我不知道该怎么做。

以下是它的生成方式:

Return-Path: 00093b6a.000127712516@urx.com
From: =?UTF-8?B?RGVzZW52b2x2aW1lbnRvIFRlc3Rlcw==?= <bla@bla.net>
Reply-To: Test Dev <bla@bla.net>
To: bla.bla@bla.net
Message-ID: <342723268.1.1430361334441.JavaMail.bla.bla@uhew>
Subject: =?UTF-8?B?VGVzdGUgQ29uZWN0IENhcg==?=
MIME-Version: 1.0
Content-Type: multipart/mixed; 
    boundary="----=_Part_0_1634925367.1430361334427"
X-Receiver: bla.bla@bla.net
X-RPTags: 
List-Unsubscribe: <mailto:None?subject=unsubscribe:00093b6a.000127712516>
X-Envid: 00605034.000127712516
X-MsgID: 00093b6a.000127712516
x-virtual-mta: NGMistoURX
X-rpcampaign: NGZDesenv605034
X-Sender: 00093b6a.000127712516@urx.com
X-UmailPersonalization: 2388627
X-Mailer: Generator V3

在这里我希望我的信息是如何生成的:

X-Receiver: bla.bla@bla.net
X-RPTags: 
List-Unsubscribe: <mailto:None?subject=unsubscribe:00093b6a.000127712516>
X-Envid: 00605034.000127712516
X-MsgID: 00093b6a.000127712516
x-virtual-mta: NGMistoURX
X-rpcampaign: NGZDesenv605034
X-Sender: 00093b6a.000127712516@urx.com
X-UmailPersonalization: 2388627
X-Mailer: Generator V3
Return-Path: 00093b6a.000127712516@urx.com
From: =?UTF-8?B?RGVzZW52b2x2aW1lbnRvIFRlc3Rlcw==?= <bla@bla.net>
Reply-To: Test Dev <bla@bla.net>
To: bla.bla@bla.net
Message-ID: <342723268.1.1430361334441.JavaMail.bla.bla@uhew>
Subject: =?UTF-8?B?VGVzdGUgQ29uZWN0IENhcg==?=
MIME-Version: 1.0
Content-Type: multipart/mixed; 
    boundary="----=_Part_0_1634925367.1430361334427"

这就是我添加标题信息的方式

headerData.foreach(header => message.addHeader(header._1, header._2) )

任何想法?

提前感谢

1 个答案:

答案 0 :(得分:1)

正如其他人所说,标题顺序真的并不重要。

如果您需要在消息开头按特定顺序放置所有标头,最简单的方法是在调用super.writeTo之前,继承MimeMessage并覆盖writeTo方法以写出标头。您可能希望将标题保存在单独的List或InternetHeaders对象中。