When a message is submitted, the transport provider can create a file that is used to contain the message during transmission. Next, an OLE IStream interface is wrapped around the file. The transport provider then uses ITnef methods to write the message properties to the stream in a tagged format that enables the properties to be easily decoded by the receiving transport providers.
To represent an entire message in a single file
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 ITnef::AddProps to encode the remaining properties, including all attachments.
Call the ITnef::Finish method to encode the message into the TNEF stream after all the requested properties are added.
Call the ITnef::OpenTaggedBody method to obtain the tagged message text. This tagged text is written out to the messaging system using methods from the OLE IStream interface.
Call the IUnknown::Release method to release the ITnef object.
To process an inbound TNEF message
Get a MAPI message object from the MAPI spooler and write message header properties into the new MAPI message.
Create and initialize an IStream object to contain the TNEF data from the inbound message.
Pass the MAPI message and the IStream object to the OpenTnefStreamEx function.
Decode the information in the TNEF data by calling the ITnef::ExtractProps method. It is important to note that anything decoded by ExtractProps will overwrite properties decoded from the incoming message's envelope. That is, extracted TNEF properties will overwrite the existing properties in a message.
Process the tagged message text by calling ITnef::OpenTaggedBody and the text is parsed to recover attachment positions.