简体   繁体   中英

How to embed images in HTML email on the mail server?

How does one embedd an image in HTML so that the image is delivered with the html file content and does not need a separate trip to the server to retrieve the image? We need this to embed company logo's into signatures before they leave the mail server. We don't want to use a client side solution like thunderbird's or outlook's functionality to add signatures.

thanks

What you need to do is encode the file to Base64, and include it like this:

<img src="data:image/gif;base64,R0lGODlhUAA..(the rest of your base64 encoded file)..">

http://www.sweeting.org/mark/blog/2005/07/12/base64-encoded-images-embedded-in-html

http://dean.edwards.name/weblog/2005/06/base64-ie/

The standard solution for that is to add the image as an attachment. Every attachment has a ContentID, so you can embed the image using: <img src="cid:ContentID" /> .
This will embed the image in the email, not in the html.

I don't think the W3C HTML specs really allow you to do this.

But if you really want to, you could create a pixel-width by pixel-height table, and set the cell background colors one by one to create your image.

I reevaluated solutions for this recently.

According to this blog the support for inline attachments has been improved, new stuff was pushed to the mainline Rails repo.

I didn't check which Rails version is lucky enough to contain this change, though.

For my 2.3.x deployments I used the inline_attachment gem .

它无法完成,但这没关系,因为现代浏览器使用KeepAlive功能,以便保留与服务器的连接以进行图像加载。

Here's a handy Image to HTML converter - warning creates NASTY HTML! :)

The question that comes to my mind is - why you don't want a normal <img> tag in your html?

Attaching a image to the body of html might sound tempting, but it will definetly slow down the email downloading times, and some people use stuff like gprs connection so they want to limit their bandwidth.

IMO having images inside your html is pure evil . But that's just out of curiosity, to ask why you want such a solution - seems @nickf alredy gave you a good one :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM