Email 电子邮件中的MIME多部分

Email 电子邮件中的MIME多部分,email,mime,Email,Mime,我试图在电子邮件中嵌入图像 通过套接字将数据发送到端口25上的SMTP服务器来创建电子邮件。以下是默剧片段: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary=mixedsection; --mixedsection Content-Type: text/plain; Content-Transfer-Encoding: 8bit Content-Disposition: inline Below should be an i

我试图在电子邮件中嵌入图像

通过套接字将数据发送到端口25上的SMTP服务器来创建电子邮件。以下是默剧片段:

MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=mixedsection;

--mixedsection
Content-Type: text/plain;
Content-Transfer-Encoding: 8bit
Content-Disposition: inline

Below should be an inline embedded image

--mixedsection
Content-Type: image/png; file=ts-charts.png
Content-Transfer-Encoding: base64
Content-Disposition: inline; filename=ts-charts.png

iVBORw0KGgoAAAANSUhEUgAAAnoAAAHqCAMAAACk+hPgAAABpFBMVEX// (etc etc etc)

--mixedsection--
收到电子邮件时,第二部分(图像)似乎已转换为附件,并且从未内联显示。所有其他部分工作正常,图像正确编码为base64,因此可以打开附件。当内容配置设置为“内联”或“附件”时,文本/普通部分都能正常工作

我使用了其他邮件客户端(outlook、thunderbird)来嵌入图像,并且图像的内联显示没有问题

我甚至不能让图像以内联方式显示,即使我去掉了所有其他内容。以下内容仍作为附件接收:

MIME-Version: 1.0
Content-Type: image/png; file=ts-charts.png
Content-Transfer-Encoding: base64
Content-Disposition: inline; filename=ts-charts.png

iVBORw0KGgoAAAANSUhEUgAAAnoAAAHqCAMAAAC (etc etc)

所以问题是,我在这里遗漏了什么,以及如何让图像以内联方式显示?

出于某种原因,我无法直接从RFC标准方式让它以普通方式工作;如果有人知道如何做到这一点,请张贴

因此,我放弃了,使用内联HTML/CID嵌入图像

我是这样做的:

MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=mixedsection;

--mixedsection
Content-Type: multipart/related; boundary=relatedsection;

--relatedsection
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 8Bit
Content-Disposition: inline

<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
  </head>
  <body>
    <p><img src="cid:myembeddedimage" alt=""></p>
  </body>
</html>

--relatedsection
Content-Type: image/png; name=ts-charts.png
Content-ID: myembeddedimage
Content-Transfer-Encoding: base64
Content-Disposition: inline; filename=ts-charts.png

iVBORw0KGgoAAAANSUhEUgAAAnoAAAHqCAMAAACk+hPgAAABpFBMVEX//3 (etc etc)

--relatedsection--
--mixedsection--
通过删除文件属性并替换为名称属性:

Content-Type: image/png; name=ts-charts.png
我不相信这是一个好的或推荐的方法,但它确实有效

编辑:。。。。 就为了结束。我一辈子都不知道如何混合纯文本和HTML嵌入图像,所以选择了简单地将文本转换成HTML

这是最后一条信息:

MIME-Version: 1.0
Content-Type: multipart/related; boundary=relatedsection;

--relatedsection
Content-Type: text/html;
Content-Transfer-Encoding: 8bit
Content-Disposition: inline

<html>
   <head>
      <meta http-equiv="content-type" content="text/html;">
   </head>
   <body>
      <p> Below is an embedded image ...</p>
      <p><img src="cid:myembeddedimage" alt=""></p>
   </body>
</html>

--relatedsection
Content-Type: image/png; name=ts-charts.png
Content-ID: myembeddedimage
Content-Transfer-Encoding: base64
Content-Disposition: inline; filename=ts-charts.png
 
AHqCAMAAACk+hPgAAABpFBMVEX///8PDw8jIyPDw8OPj333mOm2ajzGtEbdPpm (etc (etc)
--relatedsection--
MIME版本:1.0
内容类型:多部分/相关;边界=相关截面;
--相关部门
内容类型:text/html;
内容传输编码:8比特
内容配置:内联
下面是一个嵌入式图像

--相关部门 内容类型:图片/png;name=ts-charts.png 内容ID:myembeddedimage 内容传输编码:base64 内容配置:内联;filename=ts-charts.png AHQCAMAACK+HPGAAABPBMVEX///8PDw8jIyPDw8OPj333mOm2ajzGtEbdPpm(等(等) --相关部门--

我必须删除外部多部分/混合,因为通过exchange服务器运行此邮件会产生附件(att0001,att0002)被附加到消息中。在thunderbird、gmail或任何在i-phone上调用的客户端上,这些重影附件都没有问题。

AFAIK图像永远不会显示在文本中。纯文本无法指示图像应该放在哪里。RFC采用一个文本部分,可能还包括HTML等其他文本形式。正如您所发现的,HTML和cid是显示随电子邮件发送的图像的方式。
MIME-Version: 1.0
Content-Type: multipart/related; boundary=relatedsection;

--relatedsection
Content-Type: text/html;
Content-Transfer-Encoding: 8bit
Content-Disposition: inline

<html>
   <head>
      <meta http-equiv="content-type" content="text/html;">
   </head>
   <body>
      <p> Below is an embedded image ...</p>
      <p><img src="cid:myembeddedimage" alt=""></p>
   </body>
</html>

--relatedsection
Content-Type: image/png; name=ts-charts.png
Content-ID: myembeddedimage
Content-Transfer-Encoding: base64
Content-Disposition: inline; filename=ts-charts.png
 
AHqCAMAAACk+hPgAAABpFBMVEX///8PDw8jIyPDw8OPj333mOm2ajzGtEbdPpm (etc (etc)
--relatedsection--