使用Exchange Web服务选择附件

问题描述 投票:1回答:1

很抱歉,如果我的帖子是重复的,我试图找到一个没有成功的解决方案。我需要阅读一个Office365电子邮件文件夹,并获取每封邮件中包含的附件​​。我使用此代码

foreach (Attachment attachment in message.Attachments)
{
    if (attachment is FileAttachment)
    {
        FileAttachment fileAttachment = attachment as FileAttachment;
        // Load the attachment into a file.
        // This call results in a GetAttachment call to EWS.
        fileAttachment.Load("C:\\temp\\" + fileAttachment.Name);

        Console.WriteLine("File attachment name: " + fileAttachment.Name);
    }
    else // Attachment is an item attachment.
    {
        ItemAttachment itemAttachment = attachment as ItemAttachment;
        // Load attachment into memory and write out the subject.
        // This does not save the file like it does with a file attachment.
        // This call results in a GetAttachment call to EWS.
        itemAttachment.Load();
        Console.WriteLine("Item attachment name: " + itemAttachment.Name);
    }
}

从这里link来执行此操作。但是,由代码一起发送者发送的“真实”附件(也包括pdf文件,xls或图像)会下载每个邮件中包含的所有元素,即徽标,html正文中的图像等。有一种方法只能选择“真实”附件,并避免下载徽标以及正文中包含的其他html元素?谢谢你的帮助。Lucius

c# exchangewebservices email-attachments
1个回答
0
投票

您应该能够基于Fileattachment类https://docs.microsoft.com/en-us/dotnet/api/microsoft.exchange.webservices.data.fileattachment?view=exchange-ews-api上的其他属性进行过滤>

例如

if(!Attachment.IsInline)

或检查ContentId是否为null等

© www.soinside.com 2019 - 2024. All rights reserved.