Mail multipart/alternative vs multipart/mixed的答案表明附件应该是multipart/alternative
消息的对等点,例如:
- 多部分/混合
- 多部分/替代
- 文本/纯文本
- 文本/html
- 一些/事情(处置:附件)
- 一些/事情(处置:附件)
- ...
- 多部分/替代
我想发送带有 html 部分的电子邮件,其中包含一些内联图像和纯文本替代方案。各个部分的首选 MIME 布局是什么?示例代码和其他问题中出现了几个选项,但哪些选项在实践中效果最好?我的倾向是这样的:
- 多部分/替代
- 文本/纯文本
- 多部分/相关
- text/html(通过 cid 引用图像)
- 图片/gif
- 图片/gif
- ...
这样,图像显然是为了呈现 html 部分。一个完整的例子是:
From: Rich Example <rich-example@example.org>
To: A Recipient <recipient@example.org>
Subject: An example of email with images and a plain alternative
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="outer-boundary"
This is a MIME-encoded message. If you are seeing this, your mail
reader is old.
--outer-boundary
Content-Type: text/plain; charset=us-ascii
This message might make you :) or it might make you :(
--outer-boundary
MIME-Version: 1.0
Content-Type: multipart/related;
type="text/html"; start="<body@here>"; boundary="inner-boundary"
--inner-boundary
Content-Type: text/html; charset=us-ascii
Content-Disposition: inline
Content-ID: <body@here>
<html>
<body>
This message might make you
<img src="cid:smile@here" alt="smile">
or it might make you
<img src="cid:frown@here" alt="frown">
</body>
</html>
--inner-boundary
Content-Type: image/gif
Content-Disposition: inline
Content-Transfer-Encoding: base64
Content-ID: <smile@here>
R0lGODlhEAAQAKEBAAAAAP//AP//AP//ACH5BAEKAAIALAAAAAAQABAAAAIzlA2px6IBw2
IpWglOvTahDgGdI0ZlGW5meKlci6JrasrqkypxJr8S0oNpgqkGLtcY6hoFADs=
--inner-boundary
Content-Type: image/gif
Content-Disposition: inline
Content-Transfer-Encoding: base64
Content-ID: <frown@here>
R0lGODlhEAAQAKEBAAAAAAD//wD//wD//yH5BAEKAAIALAAAAAAQABAAAAIzlA2px6IBw2
IpWglOvTahDgGdI0ZlGW5meKlci75drDzm5uLZyZ1I3Mv8ZB5Krtgg1RoFADs=
--inner-boundary--
--outer-boundary--