Platform SDK: MAPI

Encoding a Message with TNEF

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

  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 ITnef::AddProps to encode the remaining properties, including all attachments.
  5. Call the ITnef::Finish method to encode the message into the TNEF stream after all the requested properties are added.
  6. 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.
  7. Call the IUnknown::Release method to release the ITnef object.

To process an inbound TNEF message

  1. Get a MAPI message object from the MAPI spooler and write message header properties into the new MAPI message.
  2. Create and initialize an IStream object to contain the TNEF data from the inbound message.
  3. Pass the MAPI message and the IStream object to the OpenTnefStreamEx function.
  4. 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.
  5. Process the tagged message text by calling ITnef::OpenTaggedBody and the text is parsed to recover attachment positions.
  6. Save the message by calling IMAPIProp::SaveChanges.
  7. Release the TNEF object by calling the IUnknown::Release method.