如何确保 HTML 电子邮件中嵌入的图像显示出来?

发布于 2024-12-26 12:03:18 字数 2289 浏览 0 评论 0原文

我必须发送一封电子邮件,其中包含图片和周围的一些文字。我已经可以发送 HTML 电子邮件,附上带有 Content-ID: 的图片,然后将其引用为 “”/。可爱的。

问题 - 许多邮件客户端默认情况下不显示它。例如,默认情况下,GMail 仅显示您已向其发送至少两封电子邮件的发件人的图片。我不知道 Mozilla Thunderbird,但从客户的投诉来看,它做了类似的事情 - 图片显示为附件,不会出现在电子邮件正文中。

我做错了什么/可以做得更好吗?

这是一封电子邮件的[审查]副本:

Delivered-To: [censored]
Received: by 10.204.187.8 with SMTP id cu8cs411179bkb;
        Wed, 4 Jan 2012 05:36:05 -0800 (PST)
Received: by 10.152.106.45 with SMTP id gr13mr25346083lab.9.1325684164222;
        Wed, 04 Jan 2012 05:36:04 -0800 (PST)
Return-Path: <[censored]>
Received: from [censored] ([censored]. [[censored]])
        by mx.google.com with ESMTPS id nq10si44421925lab.26.2012.01.04.05.36.03
        (version=TLSv1/SSLv3 cipher=OTHER);
        Wed, 04 Jan 2012 05:36:03 -0800 (PST)
Received-SPF: pass (google.com: best guess record for domain of [censored] designates [censored] as permitted sender) client-ip=[censored];
Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of [censored] designates [censored] as permitted sender) smtp.mail=[censored]
Received: from [censored] ([censored]) by [censored] ([censored]) with
 Microsoft SMTP Server id 8.1.436.0; Wed, 4 Jan 2012 15:36:03 +0200
MIME-Version: 1.0
From: [censored]
To: [censored]
Date: Wed, 4 Jan 2012 15:36:02 +0200
Subject: Test
Content-Type: multipart/mixed;
    boundary="--boundary_1_5d3b21f4-0e5d-4727-a2a2-a49bb2ad5062"
Message-ID: <e42be75d-53b2-46c7-a1c6-150c95b86ba6@[censored]>
Return-Path: [censored]

----boundary_1_5d3b21f4-0e5d-4727-a2a2-a49bb2ad5062
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: base64

[snip base64 encoded HTML]
----boundary_1_5d3b21f4-0e5d-4727-a2a2-a49bb2ad5062
Content-Type: image/jpeg; name="Picture.jpg"
Content-Transfer-Encoding: base64
Content-Disposition: attachment
Content-ID: <Picture.jpg>

[snip base64 encoded JPEG]
----boundary_1_5d3b21f4-0e5d-4727-a2a2-a49bb2ad5062--

添加:给不赞成投票的人 - 尽管我这样做看到这个问题中潜在的误用,事实是这是来自合法的场景。我正在为一家办公文具供应商制作一个网络购物网站。客户希望产品页面中有一个“发送到电子邮件”按钮,以便访问者可以将有趣的产品描述发送给他们的朋友/老板/其他人。我正在尝试在电子邮件中包含产品图片。客户抱怨图像未显示。

I have to send an email which contains a picture and some text around it. I can already send a HTML email, attach a picture with Content-ID: <Picture.jpg> and then reference it as <img src="cid:Picture.jpg" alt="" />. Cute.

The problem - many mail clients don't display it by default. For example, GMail, by default, shows pictures only from senders to which you have sent at least two emails. I've no idea about Mozilla Thunderbird, but judging by the complaint of the customer, it does something similar - the picture is displayed as an attachment and does not appear in the email body.

What am I doing wrong / could do better?

Here's a [censored] copy of an email:

Delivered-To: [censored]
Received: by 10.204.187.8 with SMTP id cu8cs411179bkb;
        Wed, 4 Jan 2012 05:36:05 -0800 (PST)
Received: by 10.152.106.45 with SMTP id gr13mr25346083lab.9.1325684164222;
        Wed, 04 Jan 2012 05:36:04 -0800 (PST)
Return-Path: <[censored]>
Received: from [censored] ([censored]. [[censored]])
        by mx.google.com with ESMTPS id nq10si44421925lab.26.2012.01.04.05.36.03
        (version=TLSv1/SSLv3 cipher=OTHER);
        Wed, 04 Jan 2012 05:36:03 -0800 (PST)
Received-SPF: pass (google.com: best guess record for domain of [censored] designates [censored] as permitted sender) client-ip=[censored];
Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of [censored] designates [censored] as permitted sender) smtp.mail=[censored]
Received: from [censored] ([censored]) by [censored] ([censored]) with
 Microsoft SMTP Server id 8.1.436.0; Wed, 4 Jan 2012 15:36:03 +0200
MIME-Version: 1.0
From: [censored]
To: [censored]
Date: Wed, 4 Jan 2012 15:36:02 +0200
Subject: Test
Content-Type: multipart/mixed;
    boundary="--boundary_1_5d3b21f4-0e5d-4727-a2a2-a49bb2ad5062"
Message-ID: <e42be75d-53b2-46c7-a1c6-150c95b86ba6@[censored]>
Return-Path: [censored]

----boundary_1_5d3b21f4-0e5d-4727-a2a2-a49bb2ad5062
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: base64

[snip base64 encoded HTML]
----boundary_1_5d3b21f4-0e5d-4727-a2a2-a49bb2ad5062
Content-Type: image/jpeg; name="Picture.jpg"
Content-Transfer-Encoding: base64
Content-Disposition: attachment
Content-ID: <Picture.jpg>

[snip base64 encoded JPEG]
----boundary_1_5d3b21f4-0e5d-4727-a2a2-a49bb2ad5062--

Added: To the downvoters - although I do see the misuse potential in this question, the truth is that this is from a legitimate scenario. I'm making a web shopping site for an office stationery supplier. The client wants a "send to email" button in the product page, so that visitors can send interesting product descriptions to their friends/bosses/whatever. I'm trying to include the product picture in the email. The client is complaining that the image is not shown.

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

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

发布评论

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

评论(3

如何视而不见 2025-01-02 12:03:18

复制自此答案

Content-ID 标头的值应该位于与 message-id 格式相同,其中看起来非常像电子邮件地址 有更好的机会与大多数邮件程序一起使用。

Copied from this answer:

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. <Picture.jpg@yourmailer> has a better chance of working with most mailers.

尘曦 2025-01-02 12:03:18

大多数电子邮件客户端总是将图像隐藏在 html 电子邮件正文中,除非它是从受信任的发件人发送的。想想看,如果某个垃圾邮件网站向您发送不适当的图像,您会希望它们在您打开电子邮件时弹出吗?

您唯一能做的就是要求收件人选择电子邮件上的选项,以始终显示来自该发件人的图像。另外,根据我的经验,图像通常不会作为电子邮件附件发送,而是图像标签指向发件人托管的图像。

Most email clients will always hide the images in the body of an html email unless it is sent from a trusted sender. Think about it, if some spam site were to send you inappropriate images, would you want them to pop up when you open the email?

The only thing you can do is to ask the recipients to select the option on the email to always show images from this sender. Also, from my experience often the images are not sent as an attachment on the email, but instead the image tag points to an image hosted by the sender.

如日中天 2025-01-02 12:03:18

我认为您不能强制电子邮件客户端以某种方式显示电子邮件。想想这会带来的安全问题!
也许您可以找到在客户的客户端中配置的选项并将其推荐给他。

I do not think you can force email clients to display emails in a certain way. Just think about the security issues this would impose!
Maybe you can find out the options to configure in the customer's client and recommend them to him.

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