TnefParser Class |
Namespace: MailBee.Tnef
The TnefParser type exposes the following members.
Name | Description | |
---|---|---|
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) | |
GetAttachments(Byte, TnefExtractionOptions) |
Extracts attachments and, optionally, rich-text body from a TNEF data.
| |
GetAttachments(Stream, TnefExtractionOptions) |
Extracts attachments and, optionally, rich-text body from a TNEF stream.
| |
GetAttachments(String, TnefExtractionOptions) |
Extracts attachments and, optionally, rich-text body from a winmail.dat file.
| |
GetAttachmentsAsync |
async/await version of GetAttachments(String, TnefExtractionOptions).
| |
GetHashCode | Serves as the default hash function. (Inherited from Object.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
ToString | Returns a string that represents the current object. (Inherited from Object.) |
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.
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); } }