HOWTO: Embedding a File in a Message Programmatically

ID: Q168903

The information in this article applies to:

SUMMARY

Using Extended MAPI, it is possible to embed a file in a message so that the contents of the file are viewed when the message is opened, embedding a bitmap into the message so that the actual bitmap appears when you open the message for example.

MORE INFORMATION

Steps to Embed a File in a Message

1. Create an attachment for the message by calling the message's

   IMessage::CreateAttach method and pass NULL as the interface identifier.

2. Call IMAPIProps::SetProps to set PR_ATTACH_METHOD to ATTACH_OLE,
   indicating an OLE object.

3. Set PR_RENDERING_POSITION to indicate where the attachment should be
   displayed.

4. Call IMAPIProp::OpenProperty to open the PR_ATTACH_DATA_OBJ property
   with an IStorage object.

5. Use OleCreateFromFile to create the embedded IStorage object from
   the specified file.

6. Call the new storage object's IStorage::Commit method.

Example

The following code creates an attachment for a message, prompts the user for a file, and then embeds that file in the message. This code assumes the message has already been created. The pointer to the message is contained in the variable pMsg.

The following .lib files should be linked:

Keywords          : kbcode kbMsg kbMAPI100 
Version           : 1.0
Platform          : WINDOWS
Issue type        : kbhowto

Last Reviewed: May 25, 1997