tags:

views:

2249

answers:

7

Hi all,

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

A: 

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.

Note: The OP is asking about HTML formatted EMail, not web pages.
Eddie
+2  A: 

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.

Jack Leow
and you REALLY want to recieve emails like this? :)
kender
++! i want the same thing you are smoking ;)
miceuz
Oh come on, you can't say I wasn't being creative. :)
Jack Leow
+8  A: 

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.hedgerwow.com/360/dhtml/base64-image/demp.php

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

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

nickf
data urls dont work on IE.
mP
Does this work for emails?
Luca Matteis
the links explain how to make it work in IE. most email programs these days use the same rendering engine as one of the browsers, or indeed are in the browser, so it should work for most people.
nickf
Not really actually, HTML in emails is very much restricted compared to the one rendered in browsers.
Luca Matteis
And Outlook uses MS Word not MS IE.
David Dorward
A: 

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

Marc Novakowski
ha from the author : "it's big, bloated and slow. What use is this?In its pure form, none. At least none that I can think of."
Simon_Weaver
+1  A: 

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

kender
Email downloading is usually a background task and users are normally only notified once the mail is downloaded. I think it is better to embed images than have it download when the mail is opened. As to why? Often links to images are blocked by firewalls or not available in offline mode.
mxc
Then the @Kobi's solution seems pefect - send images as attachments and link to attachments in the email body. This way you still allow users to get the light-weight body-only
kender
I, as user of such an email client, would prefer to have a setting where I could tell the programm to either prefetch or not, depending on my trust in the sender (or spam filter or whatnot) Most important, for me, would be the "no images anytime" radio box... It's my computer, not the sender's.
lexu
Hi Lexu, I will leave that up to the developers of the mail client to implement. My concern is to have the image delivered with the mail. Most people like to receive html mail so being able to improve their expereince is important.
mxc
+4  A: 

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.

Kobi
thanks will give it a try. Emails is mainly what I am looking at
mxc
A: 

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.

Wojciech Kaczmarek