Outlook Developer Home
Outlook Programmer's Library
 
Outlook Technologies
Outlook Forms
Languages
Samples
Other Technologies

 

 

To add an embedded image to an HTML message

This technique by Outlook MVP Neo uses undocumented MAPI properties and CDO to add an embedded image file to a message and set the CID so that an HTMLBody property <img> tag can set that image as the sourc. In VBA or Visual Basic, you will need to add a reference to the CDO 1.21 library to use this procedure.

Code Sample

Notes

Under some conditions -- and we have not been able to pinpoint what -- if you merely save the message, not send it, and later open it from Drafts, the graphic appears as a normal attachment, not as an embedded graphic. Therefore, until we figure out this issue, we recommend that any project using this technique either display the item or send it. One suggestion if you are using Visual Basic to create the message is that the image may need to be in the App.Path of the VB application. 

If you want to include the image as a background, rather than as an inline image, you can simply append this tag to the existing HTMLBody property (Thanks to Leo de Keijzer for this tip!):

<BODY background=cid:myident></BODY>

To attach multiple embedded images to a message, set the value of the &H3712001E field for each file to a unique string, which you will use in the src parameter for the <img> tag for that image.

If you don't care about the message showing an attachment icon or the image not being visible to the sender, you can use code like this snippet to use the name of the attachment, which Outlook will automatically use for the cid value:

More Information

   
2002-7 TurtleFlock, LLC
All right reserved.
About OutlookCode.com

Send comments to webmaster@outlookcode.com

Designed and Implemented by TerraLink USA 

FrontPage Integration
by RobsonDesignWorks

 
 
get Sue's code | forums | share your own code | registration