Link to home
Start Free TrialLog in
Avatar of odonovanpm
odonovanpm

asked on

Embeedding Pictures in Email (VB Application)

I am building a small email application that will allow my clients to send bulk emails to their customers. I have used HTML emails before but each time I want a product image to appear on the page I reference a URL (http://www.elro.ie/Image.gif). I recently received an email that had an image embedded in it with no reference to an online gif or jpeg. The code appeared like this:

<IMG alt="" hspace=0   src="cid:45524925" align=baseline border=0>

What is the cid reference? Thanks.
Avatar of Mikal613
Mikal613
Flag of United States of America image

Avatar of RichieHindle
RichieHindle

Emails like that are in "MIME HTML" format, as described by RFC 2110 (http://www.faqs.org/rfcs/rfc2110.html).
Each image is included in the email as an attachment with a 'Content-ID: xxx' header.  The main HTML content of the email then references that ID in the 'src' attribute.  An entire MIME HTML email message might look like this (example taken from the RFC) -

From: foo1@bar.net
To: foo2@bar.net
Subject: A simple example
Mime-Version: 1.0
Content-Type: Multipart/related; boundary="boundary-example-1";
          type=Text/HTML

--boundary-example-1
Content-Type: Text/HTML; charset=US-ASCII

... text of the HTML document, which might contain a hyperlink
to the other body part, for example through a statement such as:
<IMG SRC="cid:foo4*foo1@bar.net" ALT="IETF logo">

--boundary-example-1
Content-ID: <foo4*foo1@bar.net>
Content-Type: IMAGE/GIF
Content-Transfer-Encoding: BASE64

R0lGODlhGAGgAPEAAP/////ZRaCgoAAAACH+PUNvcHlyaWdodCAoQykgMTk5
NSBJRVRGLiBVbmF1dGhvcml6ZWQgZHVwbGljYXRpb24gcHJvaGliaXRlZC4A
etc...

--boundary-example-1--
hence
Avatar of odonovanpm

ASKER

OK, I think I understand what you are trying to show me in your example... But how can I attach an image so that it will be included in the header of the message? I am not 100% sure how I am meant to create the HTML document. If I was in a HTML editor how would I go about doing this "MIME HTML" format?

I can apply the logic to my VB Application afterwards. Thanks again.
Assuming there's no build-in VB library for building these things, you'll need to either use a third party email library (eg. http://www.chilkatsoft.com/email-dotnet.asp), or build the message yourself.

Building it yourself shouldn't be hard, but I don't know much VB so I can't show you any code.  The HTML itself is standard HTML, which you'd write in any HTML editor - the only difference is the 'src' attributes of the images.  The images need encoding using base64 - I'm sure there must be built-in support for base64 in VB, or if not there'll be a free component for it.

You can use the MSHTML DOM library to find all the images in your HTML, from there get a list of the images you need to include in the message, assign them 'cid's, and change their 'src' attributes in the HTML to contain the 'cid's rather than the filenames.  Then put together the processed HTML and the images as shown above - the boundary can be anything you like, as long as it doesn't appear anywhere in the content of the message.
But how do I physically include/save the files in an email... I'm sure this is very simple but I just can't get my head around it? Could you give me HTML code showing how to include an image in an email message?
ASKER CERTIFIED SOLUTION
Avatar of RichieHindle
RichieHindle

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Aha!  I've done some further reading on this, and I've found a way that you can do this without editing the HTML.  When you embed the image, you give it a Content-Location header that matches the 'href' attribute of the 'img' tag in the HTML.  Here's that last example again, but this time the HTML is exactly as it might come out of your HTML editor.  Note the match between the IMG SRC and the Content-Location header:

To: odonovanpm
From: Richie
Subject: Smiley gif in MIME HTML version 2
Mime-Version: 1.0
Content-Type: Multipart/related; boundary="boundary-example-1";
          type=Text/HTML

--boundary-example-1
Content-Type: Text/HTML; charset=US-ASCII

<html><body>
<p>Here is an image: <IMG SRC="smile.gif"></p>
</body></html>

--boundary-example-1
Content-Location: smile.gif
Content-Type: IMAGE/GIF
Content-Transfer-Encoding: BASE64

R0lGODlhFAAYAPcAAAAAAIAAAACAAICAAAAAgIAAgACAgICAgMDAwP8AAAD/AP//AAAA//8A/wD/
/////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMwAAZgAAmQAAzAAA/wAzAAAzMwAzZgAzmQAzzAAz/wBm
AABmMwBmZgBmmQBmzABm/wCZAACZMwCZZgCZmQCZzACZ/wDMAADMMwDMZgDMmQDMzADM/wD/AAD/
MwD/ZgD/mQD/zAD//zMAADMAMzMAZjMAmTMAzDMA/zMz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