I am trying to read in emails using mailbee from a gmail inbox. The idea is to take any winmail.dat and extract its attachments and add them to the attachment pool so we don't have to do it manually. MailBee won't recognize the winmail.dat I send with my testmail as a Tnef file, (the file's type is Tnef attachment type). the IsTnef comes out as false.
I couldn't find alot of info about mailbee tnef attachments, any ideas?
This is what I got:
var attachments = message.Attachments.Cast<MailBeeAttachment>().ToList();
var encapsulated = attachments.Where(a => a.IsTnef).SelectMany(a => a.GetAttachmentsFromTnef().Cast<MailBeeAttachment>());
// Add encapsulated attachments
attachments.AddRange(encapsulated);
You probably want to continue using MailBee... but in case you are open to alternatives, let me answer this question as if you were using my open source MimeKit/MailKit libraries instead:
When MimeKit's MIME parser encounters attachments with a
Content-Type
header that matchesapplication/vnd.ms-tnef
orapplication/ms-tnef
, it will automatically use the special-purpose TnefPart class to represent that attachment.To extract the encapsulated attachments from that, you can simply use the ExtractAttachments() method which probably works a lot like MailBee's
GetAttachmentsFromTnef()
method.The translation of your code from MailBee to MimeKit would look like this:
Most likely the reason that MailBee's
IsTnef
property is returning false for you, however, is probably because theContent-Type
header doesn't match the tnef mime-types I mentioned earlier. If that is indeed the case, then the translated code I posted above will also fail under MimeKit.However...
MimeKit also provides lower-level TNEF support classes that you can use if you decide to use an alternative method for determining of a MIME part contains TNEF content.
Of course... you could also just cheat by doing this:
So the end result might look like this (if you decide to match against the FileName instead):