如何使用 EWS 托管 API 按 ID 获取附件
本文关键字:ID 获取 API 何使用 EWS 托管 | 更新日期: 2023-09-27 17:55:37
是否可以直接使用 EWS 托管 API 获取附件,而无需先获取其包含的电子邮件?
像这样:
FileAttachment attach = FileAttachment.Bind(ewsService, attachId);
我找不到任何方法。
您可以使用
ExchangeService 类 https://msdn.microsoft.com/en-us/library/office/dn600509(v=exchg.80)的 GetAttachments 方法.aspx ,这允许您将一个或多个 GetAttachment 请求批处理在一起,例如:
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");
}
}
}