MIME类型以满足HTML,电子邮件,图像和纯文本? [英] MIME type to satisfy HTML, email, images and plain text?
问题描述
Mail multipart / alternative vs multipart / mixed 的答案表明附件应该是 multipart / alternative
消息,如:
The answer to Mail multipart/alternative vs multipart/mixed suggests that attachments should be peers of the multipart/alternative
message, like:
- multipart / mixed
<
- multipart / alternative
- text / plain
- text / html
我想发送电子邮件与html部分与一些内联图像和纯文本替代。什么是各个部分的首选MIME布局?几个选项出现在示例代码和其他问题中,但在实践中最有效?我的意思是:
I'd like to send email with an html part with some inline images and a plain text alternative. What is the preferred MIME layout for the various parts? A couple of options appear in example code and in other questions, but which have worked best in practice? My inclination is this:
- multipart / alternative
- text /
- multipart / related
- text / html(通过cid引用图片)
- image / gif
- image / gif
- ...
- multipart/alternative
- text/plain
- multipart/related
- text/html (referencing the images by cid)
- image/gif
- image/gif
- ...
这样,图像显然是为了呈现html部分的目的。一个完整的例子是:
That way, the images are clearly for the purpose of rendering the html part. A full example of this would be:
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--
推荐答案
你是对的内联图像应存储在
multipart / related
mime-entity(RFC 2387)中,并提供多种内容类型选项可以使用multipart / alternative
(RFC 2046)。
要添加附件,您可以将整个结构放入multipart / mixed
中并添加附件You are right. Inline images should be stored in a
multipart/related
mime-entity (RFC 2387) and offering multiple content-type options can be done withmultipart/alternative
(RFC 2046).
For adding attachments you may put the whole structure into amultipart/mixed
and add the attachments.- multipart / mixed
- multipart / alternative
- text / plain
- multipart / related
- text / html
- image / gif
- image / gif
- multipart/mixed
- multipart/alternative
- text/plain
- multipart/related
- text/html
- image/gif
- image/gif
您还可以在文本/简单消息中使用内联图像,但并不是所有MUA都支持此功能。 (不使用或处置:inline)
You can also use inline image in text/plain messages, but not all MUA support this. (Use none or disposition: inline)
- multipart / mixed
- text / plain (文字上图)
- image / gif
- text / plain(文字下图)
我不知道一个干净的方式将其与多部分/替代HTML电子邮件相结合。
And I dont't know a clean way to combine this with a multipart/alternative HTML-email.
这篇关于MIME类型以满足HTML,电子邮件,图像和纯文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- multipart/alternative
- multipart / alternative