[英]Retrieve attachments from EWS at once using EWS Managed API 2.0
我使用EWS来检索电子邮件,但是当我想检索附件时,必须为每个附件调用以下函数:
fileAttachment.Load();
每当我这样做时,它都会进入服务器。 是否可以一次检索所有附件? 此外,是否可以检索多个邮件项目的所有附件?
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");
}
}
}
干杯格伦
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.