I\'m currently developing an Outlook Addin which saves MailItems and Attachments in my MSSQL Database.
I got a method where I save the MailItem with all it\'s attachment
This worked for me:
var test = attachments[i].PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001E");
if (string.IsNullOrEmpty((string)test))
{
//attachment
}
else
{
//embedded image
}
Use this code answered here :
if (mailItem.Attachments.Count > 0)
{
// get attachments
foreach (Attachment attachment in mailItem.Attachments)
{
var flags = attachment.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x37140003");
//To ignore embedded attachments -
if (flags != 4)
{
// As per present understanding - If rtF mail attachment comes here - and the embeded image is treated as attachment then Type value is 6 and ignore it
if ((int)attachment.Type != 6)
{
MailAttachment mailAttachment = new MailAttachment { Name = attachment.FileName };
mail.Attachments.Add(mailAttachment);
}
}
}
}
Depends on how you define 'real' or 'proper' attachments. I'm going to assume you want to disregard all images that are embedded in the email. These are also attachments but are referenced in the actual body of the html email.
See this answer for an explanation on how attachments are embedded. The key is to disregard attachments that have a Content-ID value that is referenced by an image tag within the body of the email itself.