Sending Messages by Using TNEF Custom Attachment Processing
Collapse the table of content
Expand the table of content

Sending Messages by Using TNEF Custom Attachment Processing

Last modified: December 07, 2015

Applies to: Outlook

To customize attachment processing when sending a message:

  1. Obtain a TNEF object by passing an IStream interface 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 (PidTagAttachDataBinary) or PR_ATTACH_DATA_OBJ (PidTagAttachDataObject) 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 (PidTagAttachTransportName) 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. For more information, 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.

Your transport provider should use the previously described procedure to process attachments. If that is not possible, the transport provider should use the following steps for customized attachment processing:

  1. 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.

  2. The transport provider then uses a single call to ITnef::AddProps for each attachment, passing in the TNEF_PROP_CONTAINED flag.

© 2016 Microsoft