Vsto + differentiate attachments

I need to receive and save the attachments from the mail element, but using the code below it returns all the attachments - this means that it also returns embedded images, such as the signature of the sender, with the logo, which is the image. How can I distinguish true nesting from embedded images ? I have seen a lot on the forums, but it’s still not clear to me.

public static void SaveData(MailItem currentMailItem) { if (currentMailItem != null) { if (currentMailItem.Attachments.Count > 0) { for (int i = 1; i <= currentMailItem.Attachments.Count; i++) { currentMailItem.Attachments[i].SaveAsFile(@"C:\TestFileSave\" + currentMailItem.Attachments[i].FileName); } } } } 
+8
c # outlook vsto outlook-addin
source share
1 answer

You can check if the attachment is built-in or not using the following pseudo-code from the MS Technet forums .

 if body format is plain text then no attachment is inline else if body format is RTF then if PR_ATTACH_METHOD value is 6 (ATTACH_OLE) then attachment is inline else attachment is normal else if body format is HTML then if PR_ATTACH_FLAGS value has the 4 bit set (ATT_MHTML_REF) then attachment is inline else attachment is normal 

You can access the body format using MailItem.BodyFormat and MIME attachment properties using Attachment.PropertyAccessor .

 string PR_ATTACH_METHOD = 'http://schemas.microsoft.com/mapi/proptag/0x37050003'; var attachMethod = attachment.PropertyAccessor.Get(PR_ATTACH_METHOD); string PR_ATTACH_FLAGS = 'http://schemas.microsoft.com/mapi/proptag/0x37140003'; var attachFlags = attachment.PropertyAccessor.Get(PR_ATTACH_FLAGS); 
+8
source share

All Articles