Archived Forum Post
Problem with attached email messages in an email
May 20 '16 at 08:53
I have a problem handling attached messages (MSG) in an email.
I use Chilkat 64-bit .NET 4.5 version 188.8.131.52.
When I received an email from Outlook 2013 with an attached email message the number of attachments properties for the Email object are like this:
NumAttachments is 0
NumAttachedMessages is 1
When I create an email from Outlook 2015 with an attached email message I have the following:
NumAttachments is 1
NumAttachedMessages is 1
Have you seen this before?
Furthermore, the filename of the attached email message is always "attachedFile.mht" even though the original filename is different. What is happening?
When I have more attachments to an email (1 PDF file and 1 email messages) I have trouble getting data by attachment index.
Some indexes are defined as "the Nth attached (embedded) email" and others as "the Nth attachment".
Is it possible to distinguish between indexes of attached files and attached messages?
For instance an attached message can both be the first attached message but the second attachment. This is confusing.
Hope you have time to answer my questions.
It's only possible to answer questions like this if the MIME source of the email can be viewed.
I'll try to answer as best as possible without seeing the MIME source.
- An email sub-part can be deemed both an attachment and an attached message. I believe this can happen if certain conditions strongly suggest the semantics of an attachment, such as "content-disposition: attachment", and at the same time the sub-part has a content-type of message/rfc822. To get a glimpse of the internal logic followed to determine if something is an attachment or not, you can turn on verbose logging by setting the Email.VerboseLogging property = true, then access the Email.NumAttachments property, and then examine the Email.LastErrorText. You will see the decisions making process within the LastErrorText.
- Looking at the MIME source would answer this question. There can be a "filename" attribute on the Content-Disposition header, and there can be a "name" attribute in the Content-Type header. My guess is that the original filename is either not present at all in the sub-part's header, or maybe it's only in the "name" attribute, but no "filename" attribute exists.
- If an email sub-part is both an attachment and an attached message, then it will be in both indexes. In the attachment index (0 .. email.NumAttachments, email.GetAttachmentData, email.GetAttachmentString, etc.) you access the raw bytes or text. In the attached message index (0 .. email.NumAttachedMessages, email.GetAttachedMessage) you can access the attached messages as Email objects. There is a method named email.GetAttachmentContentType(index). You could use this to ignore "message/rfc822" attachments when your app is processing attachments because you'll handle those when processing the attached messages.