TNEF Attachments Handling in Email Messages

Transport Neutral Encapsulation Format (TNEF) is a proprietary email attachment format used by Microsoft Outlook and Microsoft Exchange Server. The Aspose.Email API allows you to read email messages that have TNEF attachments and modify the contents of the attachment. The email can then be saved as a normal email or to the same format, preserving TNEF attachments. This article shows different code samples for working with messages containing TNEF attachments. This article also shows how to create TNEF EML files from Outlook MSG files.

Read a Message with TNEF Attachment

The following code snippet shows you how to read a message preserving TNEF attachments.

Read a Message without TNEF Attachment

The following code snippet shows you how to read a message without preserving TNEF attachments.

Update Resources in TNEF Attachment

The following code snippet shows you how to update resources in a TNEF attachment and preserve TNEF format.

Add Attachment to TNEF Message

The following code snippet shows you how to add new attachments to the main message containing TNEF.

Creating TNEF EML from MSG

Outlook MSGs sometimes contain information such as tables and text styles that may get disturbed if these are converted to EML. Creating TNEF messages from such MSG files allows to retain the formatting and even send such messages via the email clients retaining the formatting. The MailConversionOptions.ConvertAsTnef property is used to achieve this. The following code snippet shows you how to create TNEF EML from MSG.

For creating the TNEF, the following sample code can be used.

Identify TNEF Format Messages

The following code snippet shows you how to detect if a message is TNEF.

Identify TNEF Format Attachments

The Attachment.IsTnef property allows to detect whether the message attachment is TNEF formatted message.

var eml = MailMessage.Load(fileName);

foreach (attachment in eml.Attachments)
{
    Console.WriteLine($"Is Attachment TNEF?: {attachment.IsTnef}");
}