The requirement is to upload attachments to a server. However, we only want to upload those appears in the "Message" line (see pic below) of outlook, nothing else in the email body.
Since Outlook itself knows which attachment should be show in the line, there must be information that it uses to distinguish them internally.
So, how can I do that within my VBA program? I have tried to use MailItem.Attachments
but all attachments are there and I cannot find any property of them can be used to distinguish.
UPDATE The original title "Distinguish embadded attachments with Outlook VBA" is a bit misleading. So I have changed the title.
Outlook Screenshot:
As I can test so far, an embedded attachment always have a MIME content ID, regardless whether it appears in the mail body. So the solution is to check whether it has a content ID.
Here is an example code that counts the visible attachments:
When I run through all my outlook emails it gives the same number of attachments in the line.
UPDATE
Thanks to Dmitry Streblechenko's information, I tested Outlook with email generated by Java Email library. The result shows that when an email attachment contains an CID but not appear in the email body, it will appear in the attachments line.
UPDATE
It looks there are still some cases that this is not good enough. I have generated the following MIME email body:
Notice that I have changed the referencing image content id in the body, and the actual image have a wrong content ID (so it is not referenced). However the image is not in the main part of the email (it is in a branch of an alternative part). That makes it invisible in outlook.
So to detect we have to make sure the attachment appears in the main MIME part... Looking for ways to do so.
UPDATE
Further digging I reaches this link and I added one more test - the
PR_ATTACHMENT_HIDDEN
property.Also it is worth to say that outlook 2010 itself is not consistent. I have observed that sometimes the email list shows the attachment icon to indicate existence of attachments but there are nothing appear when opening it in an inspector.
References:
Sending Outlook Email with embedded image using VBS
MSDN - Attachment Properties
Forum - Identifying inline attachments
Some attachments always have the MIME content id, in particular messages from Lotus Notes always have that header.
The real test is to check the HTMLBody property and see if any attachments are actually referenced by the img tags. Redemption lets you distinguish attachment like that using the RDOAttachment.Hidden property.