Saving only the REAL attachments of an Outlook MailItem

后端 未结 3 1207
悲哀的现实
悲哀的现实 2021-02-08 14:10

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

3条回答
  •  醉酒成梦
    2021-02-08 14:28

    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);
                        }
    
                    }
    
                }
            }
    

提交回复
热议问题