【问题标题】:EWS Attached emails missing DatatimeReceived property after .Load()EWS 附加的电子邮件在 .Load() 之后缺少 DatatimeReceived 属性
【发布时间】:2018-05-02 05:02:09
【问题描述】:

我目前正在处理一位前同事的项目,该项目涉及将电子邮件从 Exchange 保存到我们的 ERP 系统。

但是我遇到了一个奇怪的问题。有时当系统收到一封电子邮件时,其中包含一封电子邮件作为附件。由于未设置 DataTimeReceived 日期,因此会引发错误。即使在 .Load();

 private int HandleEmail(Item item, Folder moveToFolder, Folder moveToFailedFolder, Mailbox mailbox, int fatherId = 0, string uploaderEmail = "", bool isEmbeddedMail = false)

它的工作方式。是 HandleEmail() 方法遍历原始电子邮件,直到它获得 if-check。 如果附件不是 FileAttachment,并且是 ItemAttachment。调用以下代码。

else if (attachment is ItemAttachment)
{
 var itemAttachment = attachment as ItemAttachment;
 itemAttachment.Load(new PropertySet(ItemSchema.Attachments, ItemSchema.TextBody, EmailMessageSchema.Sender, EmailMessageSchema.DisplayCc, EmailMessageSchema.DateTimeReceived, EmailMessageSchema.From, ItemSchema.MimeContent, ItemSchema.Body, ItemSchema.TextBody, EmailMessageSchema.BccRecipients, ItemSchema.Attachments));
  var item_ = itemAttachment.Item;

 HandleEmail(item_, null, null, mailbox, (int)mailid, uploaderEmail, true); // The attached email is then looped through like it is an regular email instead of like an image.
}

在此检查中。它采用项目附件并加载一个附加属性集,其中包含一些需要的数据。 最后,该方法调用它自己,但现在使用项目附件来像普通电子邮件一样阅读它。 我的问题是,一些附加的电子邮件没有设置 DatetimeReceived 属性。 相反,这个错误会显示在它的位置。

Microsoft.Exchange.Webservice.Data.ServicesObjectPropertyException

这个期望消息被抛出

You must load or assign this property before you can read its value

而且我不太明白为什么它只发生在一些附加的电子邮件中。当我查看它自己的电子邮件时,它确实有一个接收日期。但由于某种原因,我无法使用 .Load()

我尝试了一些方法,例如对 Item 和 ItemAttachment 都使用 .Load,但都没有得到任何有价值的东西。 尝试使用 service.loadpropertiesforitems() 我已经忘记了我研究过的其他一些事情,因为我在周末前几天也一直在看这个。

【问题讨论】:

  • 我有两个建议是首先尝试 EmailMessageSchema.DateTimeSent(应该与 DateTimeReceived 相同)。另一件事是启用跟踪并查看跟踪以查看实际从服务器返回的内容,也可能只是尝试加载 BasePropertySet.FirstClassProperties 而不是您的自定义集(无论如何只是为了测试该属性)。
  • @GlenScales 我决定听从你的第一个建议,到目前为止它的工作正常,所以谢谢你。但我可能也会试试你的另一个。如果您提出您的建议作为答案,我将很乐意接受。

标签: c# exchangewebservices


【解决方案1】:

我有两个建议是首先尝试 EmailMessageSchema.DateTimeSent(应该与 DateTimeReceived 相同),差异可能是在附加已发送的消息时引起的。另一件事是启用跟踪并查看跟踪以查看实际从服务器返回的内容也可能只是尝试加载 BasePropertySet.FirstClassProperties 而不是您的自定义集(无论如何只是为了测试该属性)

【讨论】:

    猜你喜欢
    • 2012-01-03
    • 2012-09-18
    • 1970-01-01
    • 2022-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-01
    相关资源
    最近更新 更多