如何创建与大多数邮件客户端兼容的带有嵌入图像的电子邮件 [英] How to create an email with embedded images that is compatible with the most mail clients
问题描述
我们创建了一个系统,允许在外发电子邮件中嵌入图像.
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?
我注意到一件事...我想这是我的问题和 Gmail 的一部分.但无论如何我想让它停止发生
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
当我收到邮件到 Gmail 时
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.
我不明白为什么会这样.它不是链接图像(来自外部 URL),并且在从 Gmail 向 Gmail 发送嵌入图像时不会发生这种情况.这就是让我觉得我可能做错了什么并且我担心它可能会影响其他收件人的原因.
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.
推荐答案
我已经成功使用了与您使用的完全相同的标题,但有以下区别:
I've had success with exactly the same headers as you're using, with the following differences:
Embedded
无效Content-Disposition
标头的值.attachment
应该没问题.inline
也应该没问题,虽然我经常看到attachment
用于multipart/related
嵌入图像.
Embedded
is not a valid value for theContent-Disposition
header.attachment
should be fine.inline
should also be fine, though I've usually seenattachment
formultipart/related
embedded images.
Content-ID
标头的值应该在 与 message-id 格式相同,反过来 看起来很像一个电子邮件地址.<083.gif@yourmailer>
有更好的机会与大多数邮件发送者一起工作.
The value of the Content-ID
header is supposed to be in the same format as a message-id, which in turn looks very much like an email address. <083.gif@yourmailer>
has a better chance of working with most mailers.
这篇关于如何创建与大多数邮件客户端兼容的带有嵌入图像的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!