如何在c#中使用EWS API 2.0从电子邮件线程下载所有附件
本文关键字:线程 电子邮件 下载 API EWS | 更新日期: 2023-09-27 18:10:48
我已经成功地从EWS设置并下载了附件,下面是我正在处理的简短代码:
EmailMessage message = EmailMessage.Bind(service, item.Id, new PropertySet(BasePropertySet.IdOnly, ItemSchema.Attachments, ItemSchema.HasAttachments));
foreach (Attachment attachment in message.Attachments)
{
if (attachment is FileAttachment)
{
string sFilePath;
FileAttachment fileAttachment = attachment as FileAttachment;
我遇到了这个问题,它只是从最新的电子邮件线程下载附件,而不是从以前的线程。看看下面的电子邮件场景,我发了一封带有附件1的电子邮件给我的朋友,他回复了附件2给我。我如何从电子邮件中检索两个附件并与它们所属的电子邮件线程关联?
电子邮件的场景:
>中写道:这是第二个带有新附件的线程
<标题>附件2 h1> 2015年9月1日星期二晚上9:53,把它藏起来标题>
检查文档附件
<标题> 附件1 标题>I figure out:
ConversationId convId = item.ConversationId;
PropertySet properties = new PropertySet(BasePropertySet.IdOnly,
ItemSchema.Subject,
ItemSchema.InReplyTo,
ItemSchema.DateTimeReceived,
ItemSchema.DateTimeSent,
ItemSchema.DisplayCc,
ItemSchema.IsFromMe,
ItemSchema.DisplayTo,
ItemSchema.HasAttachments,
ItemSchema.Attachments,
ItemSchema.UniqueBody);
// Request conversation items. This results in a call to the service.
ConversationResponse response = service.GetConversationItems
(convId,properties,null,null,
ConversationSortOrder.TreeOrderDescending);
foreach (ConversationNode node in response.ConversationNodes)
{
foreach (Item item in node.Items)
{
Console.WriteLine(" Received: " + item.DateTimeReceived);
Console.WriteLine(" Received: " + item.uniquebody);
Console.WriteLine(" Received: " + item.subject);
if (item.HasAttachments)
{
foreach(Attachment attach in item.Attachments)
{
FileAttachment fileAttachment = attach as FileAttachment;
fileAttachment.Load(sFilePath);
}
}
}
}
参考:https://msdn.microsoft.com/en-us/library/office/dn610351 (v = exchg.150) . aspx