【问题标题】:vsto + differentiate attachmentsvsto + 区分附件
【发布时间】:2012-08-28 16:02:23
【问题描述】:

我需要从邮件项目中获取并保存附件,但使用下面的代码会返回所有附件 - 这意味着它还会返回嵌入的图像,例如带有徽标的发件人签名,这是一个图像。如何区分真实附件与嵌入图像?我在论坛上看到了很多,但我仍然不清楚。

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

【问题讨论】:

    标签: c# outlook vsto outlook-addin


    【解决方案1】:

    您可以使用以下pseudo-code from 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
    

    您可以使用MailItem.BodyFormat 访问消息正文格式,使用Attachment.PropertyAccessor 访问MIME 附件属性

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-18
      • 1970-01-01
      • 1970-01-01
      • 2012-08-15
      相关资源
      最近更新 更多