Sending Messages with TNEF Custom Attachment Processing

    To customize attachment processing when sending a message
  1. Obtain a TNEF object by passing an IStream object and a message into the OpenTnefStreamEx function.
  2. Get a list of all defined properties for the message by calling the IMAPIProp::GetPropList method.
  3. 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.
  4. 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.
  5. 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.
  6. 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.
  7. Repeat the AddProps and SetProps calls for each attachment.
  8. Call the ITnef::Finish method to encode the message into the TNEF stream after all the requested properties are added.
  9. 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.
  10. Call the IUnknown::Release method to release the ITnef object.
  11. 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.