【问题标题】:Select attachments using Exchange Web Services使用 Exchange Web 服务选择附件
【发布时间】:2020-05-12 07:47:11
【问题描述】:

对不起,如果我的帖子是重复的,我试图找到解决方案但没有成功。 我需要阅读 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 元素? 谢谢你的帮助。 卢修斯

【问题讨论】:

    标签: c# exchangewebservices email-attachments


    【解决方案1】:

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

    例如

    if(!Attachment.IsInline)
    

    或检查 ContentId 是否为空等

    【讨论】:

    • 您的解决方案非常完美。非常感谢!
    猜你喜欢
    • 2011-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-23
    • 1970-01-01
    • 2011-03-21
    • 1970-01-01
    相关资源
    最近更新 更多