Don't save embed image that contain into attachements (like signature image)

前端 未结 4 1669
一向
一向 2020-12-19 15:05

I work on a VSTO in c#. When I click on button I save attachment in a folder. My problem is : when I have a rich email with an image in the signature, I have a element in my

4条回答
  •  余生分开走
    2020-12-19 15:55

    The flags workaround didn't work for me. I'm developing a solution for Outlook 2016 and I managed to filter the attachments using this code:

    foreach (Attachment attachment in mailItem.Attachments)
                {
                    //exclude inline images
                    if (!mailItem.HTMLBody.Contains(attachment.FileName))
                    {
                        //the attachment is not an inline attachment, YOUR CODE HERE
                    }
        }
    

    which is basically checking in the HTML body if each of the attachments is mentioned in a tag.


    EDIT: the previous method may skip an attachment if you type its name in the body. This is less likey to skip false positives

    if (!mailItem.HTMLBody.Contains("cid:" + attachment.FileName))
    

提交回复
热议问题