【问题标题】:Retrieve attachments from EWS at once using EWS Managed API 2.0使用 EWS 托管 API 2.0 一次从 EWS 检索附件
【发布时间】:2015-11-09 08:58:39
【问题描述】:

我正在使用 EWS 来检索电子邮件,但是当我想检索附件时,我必须为每个附件调用以下函数:

fileAttachment.Load();

每次我这样做时,它都会转到服务器。是否可以一次检索所有附件?另外,是否可以检索多个邮件的所有附件?

【问题讨论】:

    标签: c# exchangewebservices


    【解决方案1】:

    ExchangeService 对象有一个 GetAttachments 方法,它基本上允许您执行批量 GetAttachment 请求。因此,如果您想一次加载多条消息的附件,您需要执行类似的操作(首先调用 loadpropertiesforitems,它会执行批处理 GetItem 以获取 AttachmentIds)

            FindItemsResults<Item> fItems = service.FindItems(WellKnownFolderName.Inbox,new ItemView(10));
            PropertySet psSet = new PropertySet(BasePropertySet.FirstClassProperties);
            service.LoadPropertiesForItems(fItems.Items, psSet);
            List<Attachment> atAttachmentsList = new List<Attachment>();
            foreach(Item ibItem in fItems.Items){
                foreach(Attachment at in ibItem.Attachments){
                    atAttachmentsList.Add(at);
                }
            }
            ServiceResponseCollection<GetAttachmentResponse> gaResponses = service.GetAttachments(atAttachmentsList.ToArray(), BodyType.HTML, null);
            foreach (GetAttachmentResponse gaResp in gaResponses)
            {
                if (gaResp.Result == ServiceResult.Success)
                {
                    if (gaResp.Attachment is FileAttachment)
                    {
                        Console.WriteLine("File Attachment");
                    }
                    if (gaResp.Attachment is ItemAttachment)
                    {
                        Console.WriteLine("Item Attachment");
                    }
                }
            }
    

    干杯 格伦

    【讨论】:

    • 我必须为此安装 2.2,但我会把它作为答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-01
    • 2015-03-18
    • 1970-01-01
    • 2013-08-25
    • 2017-12-09
    相关资源
    最近更新 更多