将图像嵌入电子邮件

发布于 2024-11-30 12:23:01 字数 598 浏览 0 评论 0原文

我创建了一个 C# Webform 程序,用于在我的网页上向客户发送提醒电子邮件。

它在 Outlook 中运行良好。以及 FireFox 上的 Gmail。

我刚刚发现(我不使用 IE)在 gmail 的 IE 8 中它不显示图像?

它只有一个 X 和 alt 文本。

我不明白为什么 IE 8 和 gmail 不会显示图像,我已经玩了一下。

在 C# 中:

LinkedResource emo2 = new LinkedResource(logoPath);
emo2.ContentId = "logo";
emo2.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;
htmlView.LinkedResources.Add(emo2);

和在我的 HTML 文件中:

<img id="header" alt="MyWebpage" src="cid:logo" />

通过电子邮件发送新闻通讯对所有不同的客户来说都是如此令人沮丧。但我从没想过 Gmail 会成为我的问题!

I have created a C# Webform progam for sending reminder emails to clients on my webpage.

It works fine in Outlook. and in Gmail on FireFox.

I just discovered (i dont use IE) that in IE 8 in gmail it doesn't display the image?

It just has an X and alt text.

I cant figure out why IE 8 and gmail wont dispaly the images and i have played with it a bit.

in C#:

LinkedResource emo2 = new LinkedResource(logoPath);
emo2.ContentId = "logo";
emo2.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;
htmlView.LinkedResources.Add(emo2);

and in my HTML file :

<img id="header" alt="MyWebpage" src="cid:logo" />

Sending Newsletters via Email is SO frustrating with all the differnent clients. but i never thought Gmail would be my problem!

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

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

发布评论

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

评论(4

初熏 2024-12-07 12:23:01

我们有类似的要求,将图像嵌入到 HTML 电子邮件中,而不是链接到我们网站上托管的图像。主要区别在于,用户不需要在电子邮件客户端中单击“显示所有图像”,即电子邮件应立即呈现给收件人。

我们创建了嵌入图像,它在 Outlook 和其他一些电子邮件客户端中运行得很好,但我们发现一些电子邮件客户端不喜欢它们,就像您在 Gmail 中注意到的那样。经过几天的研究和尝试不同的事情后,我们得出的结论是,没有什么灵丹妙药可以让您的电子邮件在所有主要电子邮件客户端中正确显示其嵌入的图像。

我们解决并只是在我们的网站上托管图像(这意味着用户获得“显示所有图像”按钮...),并使用类似的内容:

<img src="http://website/image.jpg"/>

如果您有耐心,您可以嵌入除某些电子邮件地址之外的所有电子邮件地址的图像地址(例如@gmail.com),但我的偏好是一致性,因此只需链接到图像。

We had a similar requirement to embed images in to the HTML email instead of link to the images hosted on our website. The main difference being that the user doesn't need to click "show all images" in their email client, i.e. the email should appear immediately rendered to the recipient.

We created the embedded images and it worked great in Outlook and some other email clients, but we discovered that some email clients don't like them as you've noticed with gmail. After a couple of days researching and trying different things, we concluded that there is no silver bullet to make your email correctly show it's embedded images in all major email clients.

We settled and just hosted the images on our website (which means the user gets the "show all images" button...), and used something like:

<img src="http://website/image.jpg"/>

If you have the patience, you could embed images for all email addresses except for certain address (such as @gmail.com), but my preference would be consistency and hence just link to the images.

终止放荡 2024-12-07 12:23:01

尝试将其添加到 LinkedResource 的末尾:

logoPath, MediaTypeNames.Image.Jpeg);

当然假设您的徽标是 JPG!
另外,是 htmlView 和 AlternateView 吗?

Try adding this to the end of LinkedResource:

logoPath, MediaTypeNames.Image.Jpeg);

Assuming your logo is a JPG of course!
Also, is htmlView and AlternateView ?

一腔孤↑勇 2024-12-07 12:23:01

答案很晚,但我敢打赌您嵌入的 jpg 不是 RBG jpg,它可能是 CMYK。

Very late answer but I bet the jpg you are embedding isn't an RBG jpg, its probably CMYK.

帥小哥 2024-12-07 12:23:01

我通过查看一封在 IE 上运行的嵌入图像的现有电子邮件解决了这个问题。显然IE对于需要显示的内容非常挑剔。即使我添加了内容类型,

var imgContentType = new ContentType(MediaTypeNames.Image.Jpeg);

它也没有显示在 IE 中。然后我查看了一封现有的电子邮件,其中的图像的内容类型为“image/png; name=”image1.png”。将名称添加到内容类型后,图像就开始显示。我想 IE 需要图像扩展名以了解如何处理图像 src

I figured out the problem by looking at an existing email with embedded images that was working on IE. Apparently IE is very picky about the content that needs to be shown. Even though I was adding content type

var imgContentType = new ContentType(MediaTypeNames.Image.Jpeg);

It was not showing up in IE. Then I looked at an existing email and the Image in it had the content type "image/png; name="image1.png". Once I added the name to the content type, the images started to show up. I guess IE needs the image extension to know what to do with the image src

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