TnefParser Class
Provides methods to parse winmail.dat (MS-TNEF) files.
Inheritance Hierarchy
SystemObject
  MailBee.TnefTnefParser

Namespace: MailBee.Tnef
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.4 build 677 for .NET 4.5
Syntax
public class TnefParser

The TnefParser type exposes the following members.

Methods
  NameDescription
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodStatic memberGetAttachments(Byte, TnefExtractionOptions)
Extracts attachments and, optionally, rich-text body from a TNEF data.
Public methodStatic memberGetAttachments(Stream, TnefExtractionOptions)
Extracts attachments and, optionally, rich-text body from a TNEF stream.
Public methodStatic memberGetAttachments(String, TnefExtractionOptions)
Extracts attachments and, optionally, rich-text body from a winmail.dat file.
Public methodStatic memberGetAttachmentsAsync
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Remarks

Usually, you'll use GetAttachmentsFromTnef methods of Attachment class to extract contents from winmail.dat attachments in e-mail messages. However, in case if you already have winmail.dat file as a separate entity (not part of an e-mail message), you can use the methods of this class.

MailBee.NET TNEF parser can also extract attachments from nested winmail.dat files. Once you call GetAttachments(Stream, TnefExtractionOptions), you can iterate through the returned AttachmentCollection and check each individual Attachment object for IsMessageInside set to true. Then use GetEncapsulatedMessage method to get the contents of the nested winmail.dat, and its Attachments collection to get the attachments (or other properties like BodyHtmlText or BodyPlainText to get text body). This works for any number of nesting levels.

TNEF parser can also extract RTF body as richbody.rtf attachment (if it's present in winmail.dat). This works for nested winmail.dat files as well.

All the methods are static (Shared in Visual Basic), you don't need to create an instance of this class. Setting MailBee.NET license key is not required either.

Examples
This example saves all attachments and RTF bodies in winmail.dat itself and in any e-mails nested in this winmail.dat.
using System;
using MailBee.Mime;
using MailBee.Tnef;

class Sample
{
    static void RecursivelySaveAllAttachmentsFromTnef(AttachmentCollection attachs)
    {
        foreach (Attachment att in attachs)
        {
            Console.WriteLine(att.Filename);
            if (att.IsMessageInside)
            {
                Console.WriteLine("Nested mail message in winmail.dat");
                MailMessage innerMsg = att.GetEncapsulatedMessage();
                RecursivelySaveAllAttachmentsFromTnef(innerMsg.Attachments);
            }
            else
            {
                // Content-type will be "application/rtf".
                if (att.Filename == "richbody.rtf")
                {
                    Console.WriteLine("Got RTF message body. Content-type: " + att.ContentType);
                }
                att.SaveToFolder(@"C:\Temp", true);
            }
        }
    }

    static void Main(string[] args)
    {
        AttachmentCollection attachs = TnefParser.GetAttachments(@"C:\Temp\winmail.dat",
            TnefExtractionOptions.ExtractAttachments | TnefExtractionOptions.ExtractRtfBody);
        RecursivelySaveAllAttachmentsFromTnef(attachs);
    }
}
See Also