使用 EWS API 从日记项目中提取附件电子邮件 - 嵌入式项目 ID 为空
Extracting attached email from a journal item with EWS API - embedded Item Id is null
我试了一整天都没有用。
我可以从 Exchange 邮箱成功检索日记项目,并访问 ItemAttachment
:
的附件
EmailMessage mailItem_Journal = EmailMessage.Bind(_service, item.Id, _propsJournalItem);
ItemAttachment itemAttachment = mailItem_Journal.Attachments[0] as ItemAttachment;
itemAttachment.Load();
Item attachedItem = itemAttachment.Item;
里面包含的 Item
是 IPM.Note 类型,即电子邮件。我需要绑定到一个 EmailMessage
对象,以便我可以访问电子邮件特定的属性,例如ToRecipients
否则不可用。
但是 attachedItem
的 Id
为 null,这导致以下失败
EmailMessage mailItem = EmailMessage.Bind(_service, attachedItem.Id, _propsEmailDetail);
Value cannot be null
我尝试绑定到 ItemAttachment
但正如预期的那样这没有用,抛出错误
Invalid Id
我猜 Id 可能是空的,因为电子邮件嵌入在另一封电子邮件中,因此不完全是 "in" 它会获得 "have" id 的任何文件夹,所以我尝试使用 Item.Save
存入邮箱,希望以后能正常取回:
attachedItem.Save(_folderItemProcessing.Id);
但是这给了我错误
This operation can't be performed because this service object already has an ID. To update this service object, use the Update() method instead.
这对我来说毫无意义,因为我的问题特别是一个空的 Id!
我不明白 Update 方法在这种情况下有什么用,所以我尝试移动项目
attachedItem.Move(_folderItemProcessing.Id);
这给了我
This operation isn't supported on attachments.
如何访问附加电子邮件的电子邮件属性?我只需要阅读它们,除了之后将父邮件移动到文件夹外,我不需要操作任何对象,我已经成功地做到了这一点。
旁注:此代码之前是使用 Outlook Redemption 库实现的,并且使用 mailItem_Journal.Attachments[1].EmbeddedMsg
成功访问了邮件,所以它一定是可能的!?
当您调用 ItemAttachment.Load
时,会将所有属性加载到项目中,无需调用 Bind
。您应该拥有所有属性,但需要将其转换为 EmailMessage
。类似于:
itemAttachment.Load();
EmailMessage attachedMsg = itemAttachment.Item as EmailMessage;
我试了一整天都没有用。
我可以从 Exchange 邮箱成功检索日记项目,并访问 ItemAttachment
:
EmailMessage mailItem_Journal = EmailMessage.Bind(_service, item.Id, _propsJournalItem);
ItemAttachment itemAttachment = mailItem_Journal.Attachments[0] as ItemAttachment;
itemAttachment.Load();
Item attachedItem = itemAttachment.Item;
里面包含的 Item
是 IPM.Note 类型,即电子邮件。我需要绑定到一个 EmailMessage
对象,以便我可以访问电子邮件特定的属性,例如ToRecipients
否则不可用。
但是 attachedItem
的 Id
为 null,这导致以下失败
EmailMessage mailItem = EmailMessage.Bind(_service, attachedItem.Id, _propsEmailDetail);
Value cannot be null
我尝试绑定到 ItemAttachment
但正如预期的那样这没有用,抛出错误
Invalid Id
我猜 Id 可能是空的,因为电子邮件嵌入在另一封电子邮件中,因此不完全是 "in" 它会获得 "have" id 的任何文件夹,所以我尝试使用 Item.Save
存入邮箱,希望以后能正常取回:
attachedItem.Save(_folderItemProcessing.Id);
但是这给了我错误
This operation can't be performed because this service object already has an ID. To update this service object, use the Update() method instead.
这对我来说毫无意义,因为我的问题特别是一个空的 Id!
我不明白 Update 方法在这种情况下有什么用,所以我尝试移动项目
attachedItem.Move(_folderItemProcessing.Id);
这给了我
This operation isn't supported on attachments.
如何访问附加电子邮件的电子邮件属性?我只需要阅读它们,除了之后将父邮件移动到文件夹外,我不需要操作任何对象,我已经成功地做到了这一点。
旁注:此代码之前是使用 Outlook Redemption 库实现的,并且使用 mailItem_Journal.Attachments[1].EmbeddedMsg
成功访问了邮件,所以它一定是可能的!?
当您调用 ItemAttachment.Load
时,会将所有属性加载到项目中,无需调用 Bind
。您应该拥有所有属性,但需要将其转换为 EmailMessage
。类似于:
itemAttachment.Load();
EmailMessage attachedMsg = itemAttachment.Item as EmailMessage;