0

I'm working on Outlook VSTO project, where I have to save all attachments of an email to a specific folder. I am looping through the attachments and checking their type like this:

Outlook.Inspector currentInspector = outlookApp.ActiveInspector();
var selectedMail = currentInspector.CurrentItem as Outlook.MailItem;

foreach (Outlook.Attachment attachment in selectedMail.Attachments)
{
    var attachmentType = attachment.Type; // this is "olByValue" all the time -- in case of embedded images, as well as actual attachments
}

(selectedMail.Attachments contains actual attachments, as well as embedded/pasted pictures in the body of the email).

Is there a way to distinguish an attachment from an embedded image here?

Right now the approach I'm using to filter out embedded images is to check if file is less than 20KB and is an image, exclude it. But it's not perfect as if someone actually attached an image less than 20KB to an email, this would exclude it.

Vakho Akobia
  • 304
  • 1
  • 3
  • 13

1 Answers1

0

You need to check whether the PR_ATTACH_CONTENT_ID property (the DASL name is http://schemas.microsoft.com/mapi/proptag/0x3712001F) is set on the attachment object and then look for it in the message body. Typically the attached image used in the message body has the following syntax:

<img src="CID:your_image_content_id">

Read more about that in the Find out if an attachment is embedded or attached thread. Also the C# Embed an image in an outlook email thread explains how to embed an image, so you may find out how to do the reverse operation - check whether it is embedded.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45