Sending Messages with TNEF Custom Attachment Processing
To customize attachment processing when sending a message
Obtain a TNEF object by passing an IStream object and a message into the OpenTnefStreamEx function.
Get a list of all defined properties for the message by calling the IMAPIProp::GetPropList method.
Use IMAPIProp methods to exclude all properties supported by the messaging system. At an appropriate time write those properties to the messaging system in the format required by the messaging system.
Call the ITnef::AddProps method to add only the properties on the message — that is, none of the properties on the attachments — by setting the TNEF_PROP_MESSAGE_ONLY flag.
Call ITnef::AddProps with these items: the TNEF_PROP_EXCLUDE flag, a property tag array that contains the PR_ATTACH_DATA_BIN or PR_ATTACH_DATA_OBJ property, and an attachment identifier that specifies the attachment to be processed.
Use the ITnef::SetProps method to add the PR_ATTACH_TRANSPORT_NAME property tag with a unique string that identifies the attachment to the messaging system if the attachment has a filename that the messaging system cannot support. For example, multiple attachments with the same original filename, or a filename that is not a valid filename for the messaging system. This string will be used with a key number when writing the attachment tags in the tagged message text to associate an attachment with its data. See, TNEF Tagged Message Text.
Repeat the AddProps and SetProps calls for each attachment.
Call the ITnef::Finish method to encode the message into the TNEF stream after all the requested properties are added.
Obtain the tagged message text by calling the ITnef::OpenTaggedBody method. This tagged text is read using methods from the IStream interface, encoded using the messaging system's attachment model, and written out to the messaging system.
Call the IUnknown::Release method to release the ITnef object.
Write the remaining attachments to the messaging system through the messaging system's attachment model.
It is highly recommended that your transport provider use the method just described to process attachments. If that is not possible, a second method for customized attachment processing is available:
The transport provider ensures that the PR_ATTACH_TRANSPORT_NAME properties of all the attachments contain unique values that are valid attachment identifiers for the messaging system. The transport provider then uses a single call to ITnef::AddProps for each attachment, passing in the TNEF_PROP_CONTAINED flag.