Last modified: September 24, 2010

Applies to: Office 2010 | Outlook 2010 | Visual Studio

Called by a transport provider to initiate a MAPI Transport Neutral Encapsulation Format (TNEF) session.

Header file:


Implemented by:


Called by:

Transport providers

HRESULT OpenTnefStream(
  LPVOID lpvSupport,
  LPSTREAM lpStream,
  LPSTR lpszStreamName, 
  ULONG ulFlags,
  LPMESSAGE lpMessage,
  WORD wKey,


Passes a support object or passes in NULL. If NULL, the value of the lpadrbook parameter should be non-null.


[in] Pointer to a storage stream object OLE IStream interface providing a source or destination for a TNEF stream message.


[in] Pointer to the name of the data stream that the TNEF object uses. If the caller has set the TNEF_ENCODE flag (ulFlags parameter) in its call to OpenTnefStream, the lpszName parameter must specify a non-null pointer to a non-null string consisting of any characters considered valid for naming a file. MAPI does not allow string names including the characters "[", "]", or ":", even if the file system permits their use. The size of the string passed for lpszName must not exceed the value of MAX_PATH, the maximum length of a string that contains a path name.


[in] Bitmask of flags used to indicate the mode of the function. The following flags can be set:


All possible properties are mapped into their down-level attributes, but when there is a possible data loss due to the conversion to a down-level attribute, the property is also encoded in the encapsulations. Note that this will cause the duplication of information in the TNEF stream. TNEF_BEST_DATA is the default if no other modes are specified.


Provides backward compatibility with the older client applications. TNEF streams encoded with this flag will map all possible properties into their corresponding down-level attribute. This mode also causes the defaulting of some properties that are required by down-level clients. This flag is obsolete and should not be used.


The TNEF object on the indicated stream is opened with read-only access. The transport provider must set this flag if it wants the function to initialize the object for subsequent decoding.


The TNEF object on the indicated stream is opened for read/write permission. The transport provider must set this flag if it wants the function to initialize the object for subsequent encoding.


Encodes all properties into the MAPI encapsulation blocks. Therefore, a "pure" TNEF file will consist of, at most, attMAPIProps, attAttachment, attRenddata, and attRecipTable. This mode is ideal for use when no backward compatibility is required.


[in] Pointer to a message object as a destination for a decoded message with attachments or a source for an encoded message with attachments. Any properties of a destination message might be overwritten by the properties of an encoded message.


[in] A search key that the TNEF object uses to match attachments to the text tags inserted in the message text. This value should be relatively unique across messages.


[out] Pointer to the new TNEF object.


The call succeeded and has returned the expected value or values.

A TNEF object created by the OpenTnefStream function later calls the OLE method IUnknown::AddRef to add references for the support object, the stream object, and the message object. The transport provider can release the references for all three objects with a single call to the OLE method IUnknown::Release on the TNEF object.

OpenTnefStream allocates and initializes a TNEF object ITnef interface for the provider to use in encoding a MAPI message IMessage interface into a TNEF stream message. Alternatively, the function can set up the object for the provider to use in subsequent calls to ITnef::ExtractProps to decode a TNEF stream message into a MAPI message. To free the TNEF object and close the session, the transport provider must call the inherited IUnknown::Release method on the object.

A Windows program should call OpenTnefStream as defined in the syntax, using the name provided.

This function is the original entry point for TNEF access and has been replaced by OpenTnefStreamEx but is still used for compatibility for those already using TNEF.