如何使用 EWS Managed API 按 ID 获取附件?
How to get attachment by id using EWS Managed API?
是否可以直接使用 EWS Managed API 获取附件,而无需先获取其包含的 EmailMessage?
类似于:
FileAttachment attach = FileAttachment.Bind(ewsService, attachId);
我找不到任何方法。
您可以使用 ExchangeService Class https://msdn.microsoft.com/en-us/library/office/dn600509(v=exchg.80).aspx 的 GetAttachments 方法,这允许您将一个或多个 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");
}
}
}
是否可以直接使用 EWS Managed API 获取附件,而无需先获取其包含的 EmailMessage?
类似于:
FileAttachment attach = FileAttachment.Bind(ewsService, attachId);
我找不到任何方法。
您可以使用 ExchangeService Class https://msdn.microsoft.com/en-us/library/office/dn600509(v=exchg.80).aspx 的 GetAttachments 方法,这允许您将一个或多个 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");
}
}
}