5

Simple question. I have a C# application that access an IMAP server using the AE.Net.Mail library to retrieve messages and attached files. Sometimes, when a message is sent from Outlook the attachments are contained in a file named winmail.dat. That is a file in the TNEF format.

Is there a library or any other way for my application to "unpack" theses files so I can get the attachments?

BastianW
  • 2,628
  • 7
  • 29
  • 38
Mathieu Pagé
  • 10,764
  • 13
  • 48
  • 71

6 Answers6

3

I've just recently implemented TNEF support in MimeKit which is based on Microsoft's Exchange TNEF API, thus allowing full access to all of the data contained within.

jstedfast
  • 35,744
  • 5
  • 97
  • 110
2

I had the same problem and ended up creating an entire email library for .NET called OpaqueMail.

It has support for parsing TNEF-encoded files (e.g. Winmail.dat) via its TnefEncoding class.

Check out this example.

// Instantiate a TNEF Encoding object to process the byte array "tnefEncoddedBytes".
TnefEncoding tnefEncoding = new TnefEncoding(tnefEncodedBytes);

// Loop through the TNEF-encoded attachments, outputting their names, content types, and sizes.
foreach (MimePart mimePart in tnefEncoding.MimeAttachments)
{
    Console.WriteLine("MIME Part Name: " + mimePart.Name);
    Console.WriteLine("MIME Part Content Type: " + mimePart.ContentType);
    Console.WriteLine("MIME Part Size: " + mimePart.BodyBytes.Length);
}
1

I've found this tool that can be controled from the command line to extract attacheemnts, from a TNEF file, but I would really prefer a library that would run "in process".

Mathieu Pagé
  • 10,764
  • 13
  • 48
  • 71
  • I accepted my own answer because that is what I eventually used, but feel this is more an effective hack rather than a solution. – Mathieu Pagé Jul 28 '12 at 03:32
0

A quick search leads to this : Yerase's TNEF Stream Reader

The project has source code, you can either reproduce it in C# or make a small C# (or better, C++/CLI) wrapper to use it.

aybe
  • 15,516
  • 9
  • 57
  • 105
0

If its for Linux platform, then you could use tnef tool

TNEF

Usage to get the Body from winmail.dat : tnef -w --save-body winmail.dat Usage to extract only the attachments from winmail.dat file: tnef winmail.dat

Tnef extracts the Body/atatchments into our current directory where we are running this tool. Or else we could give the -C DIR, --directory=DIR to save them into the specified path

Suresh
  • 277
  • 1
  • 4
  • 22
-1

TnefReader Class could be of help.

esskar
  • 10,638
  • 3
  • 36
  • 57
  • 1
    I found this during my research. Unfortunately, the dll containing the Microsoft.Exchange namespace is not redistributable. – Mathieu Pagé Jul 19 '12 at 03:46