1

I'm exporting emails by Exchange 2016 transport agent and saving them to disk. Outlook successfully opens all the emails, resolve headers, but ts is not able to show body of messages sent from Outlook client. Type is:

Content-Type: application/ms-tnef; name="winmail.dat"

Other types (MIME etc.) are OK. Exported messages do contain body. I'm able to convert it to .msg and all works after this operation. Why is this happening?

Email export method:

  using (var stream = new MemoryStream())
  {
    email.MimeDocument.WriteTo(stream);
    storageManager.SaveStreamToFile(stream, path);
    size = stream.Length;
  } 

I've alredy tried using various events of transport pipeline (https://technet.microsoft.com/en-us/library/bb125012(v=exchg.150).aspx). This question was asked on different forums, but there is no real answer. I'll provide an example of email if you want me to.

Miroslav Adamec
  • 1,060
  • 1
  • 15
  • 23

1 Answers1

0

The TNEF (Transport Neutral Encapsulation Format) is a proprietary email attachment format used by Microsoft [more technical infos here]. If you do not handle that correctly you will end up in an winmail.dat as an attachment [explained here].

To get the content from the winmail.dat you have multiple options now:

  1. Try to parse it like explained here.
  2. Use Yerase's TNEF Stream Reader [maybe the best option]
  3. Use OpaqueMail [might not work with your transport agent approach]
  4. Try to use the TnefReader Class
  5. Rebuild your solution and use Exchange EWS (= Exchange Web Services)
BastianW
  • 2,628
  • 7
  • 29
  • 38
  • 1
    This is not answer to my qeustiom. I know, how to read TNEF a I don't want to use EWS. I just cannot understand why Outlook is not able to read exported email by default. – Miroslav Adamec Apr 26 '17 at 08:48