如何控制邮件头的对齐?

时间:2012-02-25 05:09:05

标签: java smtp javamail sendmail

我遇到一种情况,当我发送一封电子邮件超过80个字符的电子邮件时,有时电子邮件主题将插入“标签”字符。我检查无效电子邮件的邮件标题,它们是对齐的,如果邮件标题条目超过80个字符,它将换行到新行,并插入“标签”。我不知道哪个配置控制它,javaMail设置? SMTP设置?

示例标题:

案例一:invaild电子邮件主题,插入一个char'标签'。

Received: from as09.aaaaaaaaa.com ([192.168.1.129]) by aaaaaaaaa.com
    ([192.168.1.49]) with ESMTP (TREND IMSS SMTP Service 7.0; TLS:
    TLSv1/SSLv3,168bits,DES-CBC3-SHA) id ba8afe04001a23ba ; Wed, 1 Feb 2012
    16:17:10 +0800
Received: from as09 (localhost [127.0.0.1])by as09.aaaaaaaaa.com
    (8.13.8+Sun/8.13.8) with ESMTP id q118HAgi021891;Wed, 1 Feb 2012 16:17:10
    +0800 (HKT)
Message-ID: <25866052.1328084230581.JavaMail.oracle@as09>
Date: Wed, 1 Feb 2012 08:17:10 +0000
From: <sss@abc.com>
To: ben@abc.com,
    john@abc.com,
    jimmy@abc.com
Subject: test Daily report for city pairs of iPhone App enquiries indocument
     version Demo Customer/Test/Test/123/1231
CC: sam@abc.com
MIME-Version: 1.0

案例二:有效的电子邮件主题,仅包装

Received: from as08.aaaaaaaaa.com ([192.168.1.104]) by aaaaaaaaa.com
 ([192.168.1.49]) with ESMTP (TREND IMSS SMTP Service 7.0; TLS:
 TLSv1/SSLv3,168bits,DES-CBC3-SHA) id c356e969001b37a5 ; Fri, 3 Feb 2012
 09:16:58 +0800
Received: from as08.aaaaaaaaa.com (localhost [127.0.0.1])   by
 as08.aaaaaaaaa.com (8.13.4+Sun/8.13.4) with ESMTP id q131Gw1l006160;   Fri, 3
 Feb 2012 09:16:58 +0800 (HKT)
Message-ID: <17351450.1328231818282.JavaMail.oracle@as08.aaaaaaaaa.com>
Date: Fri, 3 Feb 2012 01:16:58 +0000
From: <sss@abc.com>
To: ben@abc.com
Subject: test Daily report for city pairs of iPhone App enquiries in
 document version Demo Customer/Test/Test/123/1231
CC: sam@abc.com

示例java代码:

public void sendEmail(Request req) throws Exception {
  Session mailSession;
  MimeMessage msg;
  Properties mailSessionProp = new Properties();
  mailSessionProp.put("mail.smtp.host", "localhost");
  mailSessionProp.put("mail.smtp.port", "25");

  mailSession = Session.getInstance(mailSessionProp, null);
  msg = new MimeMessage(mailSession);
  msg.addRecipients("TO", InternetAddress.parse(req.getRecipientAddress()));
  msg.setSubject(MimeUtility.encodeText(req.getSubject(), "UTF-8", "B"));
  msg.setHeader("X-Mailer", "");
  msg.setSentDate(new Date());
  msg.setContent(req.getMessage(), req.getMessageContentType().getType());
  Transport.send(msg);
}

JavaMail的:

    Manifest-Version: 1.0
    Implementation-Version: 1.3.3_01
    Specification-Title: JavaMail(TM) API Design Specification
    Specification-Version: 1.3
    Extension-Name: javax.mail
    Created-By: 1.3.1 (Sun Microsystems Inc.)
    Implementation-Vendor-Id: com.sun
    Implementation-Vendor: Sun Microsystems, Inc.
    Specification-Vendor: Sun Microsystems, Inc.
    SCCS-ID: @(#)javamail.mf    1.5 02/03/14

2 个答案:

答案 0 :(得分:1)

调用setSubject()时,

JavaMail将包装头,并在调用getSubject()时将其解包。

答案 1 :(得分:1)

根据http://www.faqs.org/rfcs/rfc2822.html

,此行为是正确的
  

2.2.3。长标题字段

     

每个标题字段在逻辑上是一行字符,包括字段名称,冒号和字段正文。但是为了方便起见,为了处理每行的998/78字符限制,标题字段的字段正文部分可以拆分为多个      线表示;这被称为“折叠”。一般规则是,无论此标准允许折叠空白区域(不仅仅是WSP字符),都可以在任何WSP之前插入CRLF。