Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Embeedding Pictures in Email (VB Application)

Posted on 2004-10-15
9
Medium Priority
?
201 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 
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 2000 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
Content-ID: <smileyface>
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: 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

688 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