mxc
mxc

Reputation: 1003

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

Upvotes: 5

Views: 12435

Answers (7)

nickf
nickf

Reputation: 546443

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/

Upvotes: 8

Wojciech Kaczmarek
Wojciech Kaczmarek

Reputation: 2342

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.

Upvotes: 0

Kobi
Kobi

Reputation: 138137

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.

Upvotes: 8

kender
kender

Reputation: 87261

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

Upvotes: 0

Marc Novakowski
Marc Novakowski

Reputation: 45408

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

Upvotes: 0

Jack Leow
Jack Leow

Reputation: 22497

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.

Upvotes: 5

Two Bit Gangster
Two Bit Gangster

Reputation: 993

It can't be done, but that's OK because modern browsers use a KeepAlive feature so that the connection to the server is retained for image loading.

Upvotes: 0

Related Questions