Iterate through collection of attachments

P

PromisedOyster

In my Outlook.Attachment collection I want to be able to distinguish
between real attachments as opposed to images that have been embedded
in the message body. However, in the attachment collection of objects,
I am not sure how I can do this as they are all just treated as
attachments and there is no distinguishing feature that I acn see to
tell them apart. File type will not suffice I dont think?

Outlook.MailItem mi = (get MSG file from database);

// Iterate through the attachments
foreach (Outlook.Attachment att in mi.Attachments)
{
// I only want to save real attachments, eg if (att.RealAttachment)
att.SaveAsFile(attFile);
}
 
K

Ken Slovak - [MVP - Outlook]

Outlook version? If you are using Outlook 2007 you can use the
PropertyAccessor of the Attachment object to check for PR_ATTACH_CONTENT_ID,
which is only there as a property for embedded attachments. That has a DASL
property tag of "http://schemas.microsoft.com/mapi/proptag/0x3712001E" or
"urn:schemas:mailheader:content-id".

If you aren't using Outlook 2007 you'd need to use an alternate API such as
Redemption (www.dimastr.com/redemption) to get at that property. CDO 1.21 or
Extended MAPI aren't options for managed code.
 
D

Dmitry Streblechenko

Keep in midn tha tsome attachments have PR_ATTACH_LOCATION.
Some other attachment have nothign but a regular fiel
name(PR_ATTACH_LONG_FILENAME), but are still hidden. You' really need to
parse the HTML body to see if it refers to the attachments.
Also note that Redemption exposes RDOAttachment.Hidden property that takes
all of that into account.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
 
K

Ken Slovak - [MVP - Outlook]

True, those other properties are sometimes there for embedded attachments. A
complete test would look at all of them or use the RDO property. Most of the
time I've seen only PR_ATTACH_CONTENT_ID however.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top