如何创建与大多数邮件客户端兼容的嵌入图像的电子邮件

发布于 09-28 20:10 字数 1873 浏览 7 评论 0原文

我们创建了一个系统,允许在发出的电子邮件中嵌入图像。

这是我们的系统创建的原始消息。此示例包含图像附件和嵌入图像。

Mime-Version: 1.0
From: ...
To: ...
CC: 
Subject: test
x-sender: ...
x-mailer: ...
Content-Type: multipart/mixed; boundary="-------------...A128803765634794"

---------------...A128803765634794
Content-Type: multipart/related; boundary="-------------...B128803765634796"

---------------...B128803765634796
Content-Type: text/html; charset="UTF-8"

<p style="margin: 0; padding: 0"><img src="cid:083.gif" alt="" /></p>

---------------...B128803765634796
Content-type: image/gif; name="083.gif"
Content-ID: <083.gif>
X-Attachment-Id: 083.gif
Content-Disposition: Embedded; filename="083.gif"
Content-transfer-encoding: base64

............................................................................
............................................................................
......................................................
---------------PineappleCodeB128803765634796--
---------------PineappleCodeA128803765634794
Content-type: image/gif; name="waiting.gif"
Content-Disposition: Attachment; filename="waiting.gif"
Content-transfer-encoding: base64

............................................................................
............................................................................
......................................................
---------------PineappleCodeA128803765634794--

我还应该添加另一个标题或应该遵循的规则吗?

我注意到一件事...我猜这部分是我的问题,部分是 Gmail 的问题。但无论如何我想让它停止发生

当电子邮件被接收到Gmail时我得到

图像未显示。
显示下面的图像 - 始终显示来自...的图像

然后嵌入的图像将显示为图像附件(就像我的其他图像附件一样)

我单击“显示下面的图像”,我的图像将显示在电子邮件正文中,但不会从电子邮件中删除附件部分。

如果我返回收件箱并返回电子邮件,它看起来不错。

我不明白为什么要这样做。它不是链接图像(来自外部 URL),并且将嵌入图像从 Gmail 发送到 Gmail 时不会发生这种情况。这让我觉得我可能做错了什么,我担心这可能会影响其他收件人。

We have created a system that allows embedding an image in an outgoing email.

Here is the original message our system creates. This example contains an image attachment and an embedded image.

Mime-Version: 1.0
From: ...
To: ...
CC: 
Subject: test
x-sender: ...
x-mailer: ...
Content-Type: multipart/mixed; boundary="-------------...A128803765634794"

---------------...A128803765634794
Content-Type: multipart/related; boundary="-------------...B128803765634796"

---------------...B128803765634796
Content-Type: text/html; charset="UTF-8"

<p style="margin: 0; padding: 0"><img src="cid:083.gif" alt="" /></p>

---------------...B128803765634796
Content-type: image/gif; name="083.gif"
Content-ID: <083.gif>
X-Attachment-Id: 083.gif
Content-Disposition: Embedded; filename="083.gif"
Content-transfer-encoding: base64

............................................................................
............................................................................
......................................................
---------------PineappleCodeB128803765634796--
---------------PineappleCodeA128803765634794
Content-type: image/gif; name="waiting.gif"
Content-Disposition: Attachment; filename="waiting.gif"
Content-transfer-encoding: base64

............................................................................
............................................................................
......................................................
---------------PineappleCodeA128803765634794--

Is there another header I should add or rule I should follow?

I noticed one thing... I would guess that it is part my issue and part Gmails. but at any rate I would like to make it stop happening

When the email is received into Gmail I get

Images are not displayed.
Display images below - Always display images from ...

The embedded image is then shown as an image attachment (just like my other image attachment)

I click Display Images Below and my image is shown in the body of the email but not removed from the Attachments section.

If I go back to my in box and back to the email it looks fine.

I do not see why it does that. It it not a linked image (from external URL) and it does not happen when sending embedded images from Gmail to Gmail. That is what makes me think I might be doing somthing wrong and I am afraid that it may affect other recipients.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我不是你的备胎 2024-10-05 20:10:39

我已经成功使用与您使用的完全相同的标头,但存在以下差异:

I've had success with exactly the same headers as you're using, with the following differences:

╭ゆ眷念 2024-10-05 20:10:39

我在 Gmail 中加载内联图像时遇到问题,并且发现我错误地使用了 PHP 中的 PEAR Mail_Mime 库。
如前所述,Content-ID 的格式必须类似于消息 ID。
如果未提供,PEAR Mail_Mime 库将尝试将domainID 添加到您的Content-ID 中。
它还会尝试使用正则表达式替换电子邮件 HTML 正文中的这些 Content-ID,以维护链接。就我而言,此步骤失败,最终破坏了从 HTML 标记到 MIME 附件的链接。因此 Gmail 拒绝内嵌显示图像是完全正确的。但它确实将图像显示为附件。

I was having trouble loading inline images in Gmail and I found that I was mis-using the PEAR Mail_Mime library in PHP.
As already noted, the Content-ID must be formatted like a message id.
The PEAR Mail_Mime library will try to add a domainID to your Content-ID if one is not supplied.
It will also attempt to regex replace these Content-ID's in the HTML body of the email to maintain the link. In my case, this step was failing which did end up breaking the link from the HTML tag to the MIME attachment. So it was perfectly correct for Gmail to refuse to display the image inline. It did display the image as an attachment however.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文