【发布时间】:2014-10-15 07:51:03
【问题描述】:
使用 JavaMail,我正在构建具有以下格式的消息
+------------------------------------------------+
| multipart/related |
| +---------------------------+ +-------------+ |
| |multipart/alternative | | attachments | |
| | +-----------+ +---------+ | | | |
| | |text/plain | |text/html| | | | |
| | +-----------+ +---------+ | | | |
| +---------------------------+ +-------------+ |
+------------------------------------------------+
ASCII 艺术归因于该问题的 OP:http://www.coderanch.com/t/503380/java/java/Java-Mail-text-html-attachment
我觉得这将是正确的格式,因为附件(图像/gif、应用程序/pdf 等)对于理解整个消息很重要。但是,我一直在做一些研究,发现经常使用multipart/mixed。
我应该用multipart/mixed 替换multipart/related 部分吗?如果是,为什么?
此格式的示例消息如下:
Content-Type: multipart/related;
boundary="----=_Part_6818257_562311419.1408632937947"
------=_Part_6818257_562311419.1408632937947
Content-Type: multipart/alternative;
boundary="----=_Part_6818256_1953685207.1408632937947"
------=_Part_6818256_1953685207.1408632937947
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
This is my message!
------=_Part_6818256_1953685207.1408632937947
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit
<html><strong>This is my message!</strong></html>
------=_Part_6818256_1953685207.1408632937947--
------=_Part_6818257_562311419.1408632937947
Content-Type: application/pdf;name="document.pdf"
Content-Transfer-Encoding: base64
Content-ID: <attachment0>
X-Attachment-Id: attachment0
< insert lots of base64 encoding here >
------=_Part_6818257_562311419.1408632937947--
【问题讨论】:
-
这是一道编程题吗?
-
@Nabin 假设我们程序员在许多方面都是问题解决者,我会说,是的 :)
标签: email jakarta-mail html-email email-attachments