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

标签 email mime

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

    最佳答案

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

  • 多部分/混合
  • 多部分/替代
  • 文字/普通
  • 多部分/相关
  • 文本/html
  • 图像/gif
  • 图像/gif
  • 一些/东西(性格:附件)
  • 一些/东西(性格:附件)

  • 您还可以在文本/纯文本消息中使用内嵌图像,但并非所有 MUA 都支持此功能。 (使用 none 或 disposition: inline)
  • 多部分/混合
  • 文本/纯文本(图像上方的文本)
  • 图像/gif
  • 文本/纯文本(图片下方的文本)

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

    关于email - 满足 HTML、电子邮件、图像和纯文本的 MIME 类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10631856/

    相关文章:

    xslt - 使用XSL :FO to add attachments to PDF

    database - 如何在 laravel 4 中将邮件数据从服务提供商传递到 config/mail.php

    C# 发送群发邮件

    email - Go(lang)解析电子邮件标题并保持顺序

    c# - 垃圾邮件中发送的邮件

    types - 资源被解释为字体但使用 MIME 类型 text/html 传输不会修复

    fonts - TTF 文件的 MIME 类型是什么?

    ruby - 从电子邮件中删除签名和回复

    php - 在 Javascript 中发送动态生成的图像作为 PHP 中的图像标题

    IMAP MIME 边界生命周期