c# - 如何使用 EWS 托管 API 保存项目附件

标签 c# exchangewebservices ews-managed-api

是否可以保存一个ItemAttachment?对于 FileAttachment,我们使用以下 EWS 托管 API 代码来保存,

   if(attachment is FileAttachment)
    {
      FileAttachment fAttachment = new FileAttachment();
      fAttachment.Load("D:\\Stream" + fAttachment.Name);
    }

ItemAttachment 呢?我们如何将这样的 ItemAttachment 保存到指定的文件中?

最佳答案

当然,这仍然不是一个紧迫的问题,但我想我会分享给将来像我一样偶然发现这个问题的人。

对于 ItemAttachments,您需要加载项目的 MimeContent,然后您可以简单地写入文件/输出 [".eml", ".msg"]:

if (attachment is FileAttachment)
{
    FileAttachment fileAttachment = attachment as FileAttachment;

    // Load attachment contents into a file.
    fileAttachment.Load(<file path>);
}
else // Attachment is an ItemAttachment (Email)
{
    ItemAttachment itemAttachment = attachment as ItemAttachment;

    // Load Item with additionalProperties of MimeContent
    itemAttachment.Load(EmailMessageSchema.MimeContent);

    // MimeContent.Content will give you the byte[] for the ItemAttachment
    // Now all you have to do is write the byte[] to a file
    File.WriteAllBytes(<file path>, itemAttachment.Item.MimeContent.Content);
}

关于c# - 如何使用 EWS 托管 API 保存项目附件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14645643/

相关文章:

c# - MS Outlook 2013 删除通过 Exchange Web 服务 API 添加到 MasterCategoryList 的自定义类别

c# - EWS - 尝试加载与会者时列出日历约会失败

c# - 如何制作精简的 PropertyGrid

c# - 简单类+工厂的通用解决方案

c# - LINQ - 如何对过滤数据集的所有列求和

azure - 外部用户访问我的 Office 365 第三方应用程序 : "a User account is not registered for the account"

powershell - EWS Managed api 中是否有类似于 PowerShell 中的 Get-CalendarProcessing 方法的方法?

c# - C# Web 应用程序中的 Azure Active Directory B2C

vb.net - 邮箱和 Active Directory 帐户创建自动化

.net - 使用 Exchange Web 服务发送带有特殊字符的电子邮件