不要保存包含在附件中的嵌入图像(例如签名图像)

Joc*_*c02 4 c# vsto attachment outlook-addin

我在C#中使用VSTO。当我单击按钮时,我将附件保存在文件夹中。我的问题是:当我在签名中带有图像的丰富电子邮件时,附件中就有一个元素。但我不想保存该图像。Outlook(应用程序)将此附件隐藏在区域附件中!那么为什么不我:-(

我的代码非常简单:

MailItem MailItemSelected =  this.OutlookItem;   
foreach (Attachment a in MailItemSelected.Attachments)
{
   a.SaveAsFile(path + a.FileName);
}
Run Code Online (Sandbox Code Playgroud)

但是我没有找到不保存签名图像的测试。

小智 6

我们只需要在Outlook加载项中显示“邮件附件”(而不是用于呈现的嵌入式附件),这就是起作用的方法。

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

                }

            }
        }
Run Code Online (Sandbox Code Playgroud)