在 html 电子邮件中嵌入图像

embedding image in html email(在 html 电子邮件中嵌入图像)
本文介绍了在 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 图像.我可以将这些内容存储在我们的一台网络服务器上并直接链接到它们,但许多用户的电子邮件客户端不会自动显示它们,并且需要更改设置或为每封电子邮件手动下载它们.

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--

非常感谢.

顺便说一句:是的,我已经验证 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--

//哦,我刚刚意识到,如果您插入我帖子中的第一个代码片段以使用 Thunderbird 编写电子邮件,Thunderbird 会自动将 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 电子邮件中嵌入图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

SQL to Generate Periodic Snapshots from Transactions Table(用于从事务表生成定期快照的SQL)
MyBatis support for multiple databases(MyBatis支持多个数据库)
Oracle 12c SQL: Missing column Headers in result(Oracle 12c SQL:结果中缺少列标题)
SQL query to find the number of customers who shopped for 3 consecutive days in month of January 2020(查询2020年1月连续购物3天的客户数量)
How to get top 10 data weekly (This week, Previous week, Last month, 2 months ago, 3 month ago)(如何每周获取前十大数据(本周、前一周、上个月、2个月前、3个月前))
Select the latest record for an Id per day - Oracle pl sql(选择每天ID的最新记录-Oracle pl SQL)