【问题标题】:MIME type to satisfy HTML, email, images and plain text?MIME 类型满足 HTML、电子邮件、图像和纯文本?
【发布时间】:2012-05-24 19:14:33
【问题描述】:

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--

【问题讨论】:

  • 似乎是它引用的问题的完全欺骗:stackoverflow.com/questions/3902455/…
  • 意图上的细微差别(无论我是否清楚地传达了它)可能与附件的目的有关。如果它们是 for 丰富的渲染(例如徽标、机翼等),它们是否应该在“丰富”替代方案中?参考的问题也没有提到related

标签: email mime


【解决方案1】:

你是对的。内联图像应存储在 multipart/related mime-entity (RFC 2387) 中,并且可以使用 multipart/alternative (RFC 2046) 提供多种内容类型选项。
要添加附件,您可以将整个结构放入 multipart/mixed 并添加附件。

  • 多部分/混合
    • 多部分/替代
      • 文本/纯文本
      • 多部分/相关
        • 文本/html
        • 图片/gif
        • 图片/gif
    • 一些/事物(性格:依恋)
    • 一些/事物(性格:依恋)

您也可以在文本/纯文本消息中使用内联图像,但并非所有 MUA 都支持这一点。 (不使用或处置:内联)

  • 多部分/混合
    • text/plain(图片上方的文字)
    • 图片/gif
    • 文本/纯文本(图片下方的文本)

而且我不知道将它与多部分/替代 HTML 电子邮件结合起来的干净方法。

【讨论】:

  • 抱歉,我认为这不正确。在 multipart/alternative 里面只有两个项目:text 和 html。另一种方法是在 multipart/related 中。见:stackoverflow.com/a/40420648/633961
猜你喜欢
  • 2012-12-26
  • 2014-09-26
  • 2014-03-24
  • 2013-04-26
  • 2013-03-10
  • 1970-01-01
  • 2015-12-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多