'How do you copy RTF attachments into a new mailitem?

I am working with C# Outlook Object Model (with a little bit of C++ extended MAPI for decoding TNEF for RTF mails) and am trying to find a way to get the attachments from a mail I have used the tnef decode on (I opened this mail as a shareditem to access its contents), and add these attachments into a new mailitem. What I am observing with these attachments is that they either contain a filename with "UTF8 Hex: xxxx.msg" for message attachments, or shows null for attachment.filename, and the display name shows "UTF8 Hex: xxxx". I know these attachments without filename are pdf/docx files since I attached them myself for testing, but there's no way to identify that from the hex encoded displayname and null filename. (Where xxxx represents a long string of hexadecimals)

My usual go to when attaching HTML attachments when I am doing this is to use the attachment.FileName and do a attachment.SaveAsFile(filename), then doing a newmailitem.Attachments.Add(savedfile) but with the filename not found in the attachment and the displayname not showing anything helpful, I am lost on how I should do the same for RTF mails.

Any help would be much appreciated!



Solution 1:[1]

There is no file names for the embedded OLE attachments. They are not even files, they are IStorage objects. You can extract the the file data from the streams inside the IStorage object.

Is there a particular reason why you are parsing the TNEF data explicitly instead of using OpenTnefStreamEx?

If using Redemption (I am its author) is an option, is version of RDOAttachment.SaveAsFile extracts attachment data from the IStorage object under the hood. Also note that you don't need to deal with attachments etc. if you want to copy the whole message into another message - you can call RDOMail.CopyTo() and pass another object as a parameter.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1