Solved

Embeedding Pictures in Email (VB Application)

Posted on 2004-10-15
9
191 Views
Last Modified: 2010-04-23
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.
0
Comment
Question by:odonovanpm
  • 5
  • 2
  • 2
9 Comments
 
LVL 48

Expert Comment

by:Mikal613
ID: 12323803
0
 
LVL 14

Expert Comment

by:RichieHindle
ID: 12323840
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--
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 12323941
hence
0
 

Author Comment

by:odonovanpm
ID: 12324025
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.
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 14

Expert Comment

by:RichieHindle
ID: 12388995
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.
0
 

Author Comment

by:odonovanpm
ID: 12389408
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?
0
 
LVL 14

Accepted Solution

by:
RichieHindle earned 500 total points
ID: 12390028
> But how do I physically include/save the files in an email [...] ?

The example above does exactly that.  The piece that looks like this:

   Content-Transfer-Encoding: BASE64

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

*is* the image.  It's encoded using base64, which is an encoding technique that takes binary data like an image and encodes it as printable characters.  Email programs know how to decode that text to retrieve the original image data.  There must be a VB library to do base64 encoding.

Here's a complete example.  Save this as 'smile.mht' and double-click it in Windows Explorer.  Internet Explorer should start, and show you an HTML page with a picture of a smiley face in it.  Forgive my meagre artwork!

To: odonovanpm
From: Richie
Subject: Smiley gif in MIME HTML
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="cid:smileyface"></p></body></html>

--boundary-example-1
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v+Zmf+Z
zP+Z///MAP/MM//MZv/Mmf/MzP/M////AP//M///Zv//mf//zP///yH5BAEAABAALAAAAAAUABgA
AAhIAP8JHEiwoMGDCBMqVIgCRcGGCyESlJiQokCLBzFiNKjRIUOPAzcuHEmypMmTKCeOBBlyZUaG
CFlyrBgz4kyXLUs2FJmyZ8GAADs=

--boundary-example-1--
0
 
LVL 14

Expert Comment

by:RichieHindle
ID: 12390059
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/zMzADMzMzMzZjMzmTMzzDMz/zNmADNmMzNm
ZjNmmTNmzDNm/zOZADOZMzOZZjOZmTOZzDOZ/zPMADPMMzPMZjPMmTPMzDPM/zP/ADP/MzP/ZjP/
mTP/zDP//2YAAGYAM2YAZmYAmWYAzGYA/2YzAGYzM2YzZmYzmWYzzGYz/2ZmAGZmM2ZmZmZmmWZm
zGZm/2aZAGaZM2aZZmaZmWaZzGaZ/2bMAGbMM2bMZmbMmWbMzGbM/2b/AGb/M2b/Zmb/mWb/zGb/
/5kAAJkAM5kAZpkAmZkAzJkA/5kzAJkzM5kzZpkzmZkzzJkz/5lmAJlmM5lmZplmmZlmzJlm/5mZ
AJmZM5mZZpmZmZmZzJmZ/5nMAJnMM5nMZpnMmZnMzJnM/5n/AJn/M5n/Zpn/mZn/zJn//8wAAMwA
M8wAZswAmcwAzMwA/8wzAMwzM8wzZswzmcwzzMwz/8xmAMxmM8xmZsxmmcxmzMxm/8yZAMyZM8yZ
ZsyZmcyZzMyZ/8zMAMzMM8zMZszMmczMzMzM/8z/AMz/M8z/Zsz/mcz/zMz///8AAP8AM/8AZv8A
mf8AzP8A//8zAP8zM/8zZv8zmf8zzP8z//9mAP9mM/9mZv9mmf9mzP9m//+ZAP+ZM/+ZZv+Zmf+Z
zP+Z///MAP/MM//MZv/Mmf/MzP/M////AP//M///Zv//mf//zP///yH5BAEAABAALAAAAAAUABgA
AAhIAP8JHEiwoMGDCBMqVIgCRcGGCyESlJiQokCLBzFiNKjRIUOPAzcuHEmypMmTKCeOBBlyZUaG
CFlyrBgz4kyXLUs2FJmyZ8GAADs=

--boundary-example-1--
0
 
LVL 14

Expert Comment

by:RichieHindle
ID: 12390067
There's a free VB base64 library here: http://www.thevbzone.com/cBASE64.cls
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now