使用Exchange Web服务选择附件



很抱歉,如果我的帖子重复,我试图找到解决方案,但没有成功。我需要阅读Office365电子邮件文件夹,并获取每封邮件中包含的附件。我使用这个代码

foreach (Attachment attachment in message.Attachments)
{
if (attachment is FileAttachment)
{
FileAttachment fileAttachment = attachment as FileAttachment;
// Load the attachment into a file.
// This call results in a GetAttachment call to EWS.
fileAttachment.Load("C:\temp\" + fileAttachment.Name);
Console.WriteLine("File attachment name: " + fileAttachment.Name);
}
else // Attachment is an item attachment.
{
ItemAttachment itemAttachment = attachment as ItemAttachment;
// Load attachment into memory and write out the subject.
// This does not save the file like it does with a file attachment.
// This call results in a GetAttachment call to EWS.
itemAttachment.Load();
Console.WriteLine("Item attachment name: " + itemAttachment.Name);
}
}

从这里获取链接来完成此操作。但将发件人发送的"真实"附件(pdf文件、xls或图像(放在一起,代码会下载每封邮件中包含的所有元素,即徽标、html正文中的图像等。有没有办法只选择"真正的"附件,避免下载徽标和正文中包含的其他html元素?谢谢你的帮助。Lucius

您应该能够根据Fileattachment类上的其他属性进行筛选https://learn.microsoft.com/en-us/dotnet/api/microsoft.exchange.webservices.data.fileattachment?view=exchange-ews-api

例如

if(!Attachment.IsInline)

或者检查ContentId是否为null等

最新更新