在html电子邮件中嵌入图像 [英] embedding image in html email

查看:190
本文介绍了在html电子邮件中嵌入图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试发送带有嵌入式gif图像的多部分/相关html电子邮件。此电子邮件是使用Oracle PL / SQL生成的。我的尝试失败了,图像显示为红色X(在Outlook 2007和yahoo邮件中)

I'm trying to send a multipart/related html email with embedded gif images. This email is generated using Oracle PL/SQL. My attempts have failed, with the image showing up as a red X (in Outlook 2007 and yahoo mail)

我一直在发送html电子邮件一段时间,但我的要求现在在电子邮件中使用几个gif图像。我可以将这些存储在我们的一个Web服务器上,并且只需链接到它们,但是许多用户发送电子邮件的客户端将不会自动显示,并且需要更改每个电子邮件的设置或手动下载。

I've been sending html emails for some time, but my requirements are now to use several gif images in the email. I can store these on one of our web servers and just link to them, but many users email clients will not show them automatically and will need to either change settings or manually download them for each email.

所以,我的想法是嵌入图像。我的问题是:

So, my thoughts are to embed the image. My questions are:


  1. 我在这里做错什么?

  2. 嵌入方法是否正确一个?

  3. 如果我需要使用越来越多的图像,任何其他选项?附件将无法正常工作,因为图像通常不会在消息的上下文中有意义的徽标和图标。此外,电子邮件的一些内容是链接到在线系统,因此生成静态PDF和附件将无法正常工作(据我所知)。

片段:

MIME-Version: 1.0
To: me@gmail.com
BCC: me@yahoo.com
From: email@yahoo.com
Subject: Test
Reply-To: email@yahoo.com
Content-Type: multipart/related; boundary="a1b2c3d4e3f2g1"

--a1b2c3d4e3f2g1

content-type: text/html;

    <html>
    <head><title>My title</title></head>
    <body>
    <div style="font-size:11pt;font-family:Calibri;">
    <p><IMG SRC="cid:my_logo" alt="Logo"></p>

... more html here ...

</div></body></html> 

--a1b2c3d4e3f2g1

Content-Type: image/gif;
Content-ID:<my_logo>
Content-Transfer-Encoding: base64
Content-Disposition: inline

[base64 image data here]

--a1b2c3d4e3f2g1--

非常感谢。

BTW:是的,我有验证base64数据是否正确,因为我可以将图像嵌入到HTML本身(使用相同的算法用于创建标题数据),并在Firefox / IE中查看图像。

BTW: Yes, I have verified that the base64 data is correct, as I can embed the image in the html itself (using same algo use for creating header data) and see image in Firefox/IE.

我还应该注意到,这不是垃圾邮件,电子邮件发送给希望每天的特定客户端。内容是数据驱动的,而不是广告。

I should also note that this is NOT for spam, the emails are sent to specific clients who are expecting it daily. The content is data-driven, and not adverts.

推荐答案

尝试直接插入,这样可以插入多个图像

Try to insert it directly, this way you can insert multiple images at various locations in the email.

<img src="data:image/jpg;base64,/*base64-data-string here*/" />

为了让这篇文章对他人有用:
如果你没有base64数据字符串,轻松创建一个:
http:// www来自图像文件的.motobit.com / util / base64-decoder-encoder.asp

And to make this post usefully for others to: If you don't have a base64-data string, create one easily at: http://www.motobit.com/util/base64-decoder-encoder.asp from a image file.

电子邮件源代码看起来像这样,但我真的不能告诉你这个边界是什么:

Email source code looks something like this, but i really cant tell you what that boundary thing is for:

 To: email@email.de
 Subject: ...
 Content-Type: multipart/related;
 boundary="------------090303020209010600070908"

This is a multi-part message in MIME format.
--------------090303020209010600070908
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 7bit

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-15">
  </head>
  <body bgcolor="#ffffff" text="#000000">
    <img src="cid:part1.06090408.01060107" alt="">
  </body>
</html>

--------------090303020209010600070908
Content-Type: image/png;
 name="moz-screenshot.png"
Content-Transfer-Encoding: base64
Content-ID: <part1.06090408.01060107>
Content-Disposition: inline;
 filename="moz-screenshot.png"

[base64 image data here]

--------------090303020209010600070908--

//编辑:哦,我只是意识到如果你从我的帖子插入第一个代码片段要写一个电子邮件与雷鸟,雷鸟自动更改html代码看起来几乎与我的帖子中的第二个代码相同。

// Oh, i just realize if you insert the first code snippet from my post to write an email with thunderbird, thunderbird automatically changes the html code to look pretty much the same as the second code in my post.

这篇关于在html电子邮件中嵌入图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆