首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >满足HTML、电子邮件、图像和纯文本的MIME类型?

满足HTML、电子邮件、图像和纯文本的MIME类型?
EN

Stack Overflow用户
提问于 2012-05-17 15:55:41
回答 1查看 52.6K关注 0票数 25

Mail multipart/alternative vs multipart/mixed的回答建议附件应该是multipart/alternative消息的对等体,例如:

  • multipart/mixed
    • multipart/alternative
      • text/plain
      • text/html

代码语言:javascript
复制
- some/thing (disposition: attachment)
- some/thing (disposition: attachment)
- ...

我想发送电子邮件与html部分与一些内联图像和一个纯文本的替代方案。各个部分的首选MIME布局是什么?有几个选项出现在示例代码和其他问题中,但哪些在实践中效果最好?我的倾向是:

  • multipart/alternative
    • text/plain
    • multipart/related
      • text/html (通过cid)
      • image/gif
      • image/gif
      • ...

引用图像

这样,图像显然是为了呈现html部分。一个完整的例子是:

代码语言:javascript
复制
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--
EN

回答 1

Stack Overflow用户

发布于 2013-12-31 11:57:57

你是正确的。内联图像应该存储在multipart/related mime实体(RFC2387)中,并且可以使用multipart/alternative (RFC2046)提供多种内容类型选项。

要添加附件,您可以将整个结构放入multipart/mixed中,然后添加附件。

  • multipart/mixed
    • multipart/alternative
      • text/plain
      • multipart/related
        • text/html
        • image/gif
        • image/gif

代码语言:javascript
复制
- some/thing (disposition: attachment)
- some/thing (disposition: attachment)

您也可以在文本/纯文本消息中使用内联图像,但不是所有的MUA都支持此功能。(使用none或disposition: inline)

  • multipart/mixed image)
  • image/gif
  • text/plain上的文本( image)

下的文本)

  • 文本/纯文本

我不知道一种干净的方法来将它与一个多部分/可选的HTML-email结合起来。

票数 10
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10631856

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档