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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8804238/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 12:26:12  来源:igfitidea点击:

How to ensure that images embedded in HTML emails show up?

htmlimageemailattachmentembedding

提问by Vilx-

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.

我必须发送一封电子邮件,其中包含一张图片和一些文字。我已经可以发送 HTML 电子邮件,附加图片,Content-ID: <Picture.jpg>然后将其引用为<img src="cid:Picture.jpg" alt="" />. 可爱的。

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.

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

What am I doing wrong / could do better?

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

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

[censored]是一封电子邮件的副本:

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.

补充:对于反对者 - 尽管我确实看到了这个问题中滥用的可能性,但事实是这是来自合法的情况。我正在为一家办公文具供应商制作一个网上购物网站。客户希望在产品页面上有一个“发送到电子邮件”按钮,以便访问者可以将有趣的产品描述发送给他们的朋友/老板/任何人。我正在尝试在电子邮件中包含产品图片。客户抱怨图像未显示。

采纳答案by Danny

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?

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

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.

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

回答by Gary van der Merwe

Copied from this answer:

这个答案复制:

The value of the Content-IDheader 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.

Content-ID标头的值应该与message-id 的格式相同,而后者看起来非常像电子邮件地址<Picture.jpg@yourmailer>有更好的机会与大多数邮寄者合作。

回答by Fildor

I do not think you can forceemail 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.

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