FindItems() 和 BindToItems() 为 EmailMessage.Sender.Address 提供不一致的结果

发布于 2024-12-27 19:26:35 字数 1615 浏览 2 评论 0原文

经过大量调试后,我将复杂的托管 EWS 问题细化为以下两个简单的测试用例。第一个有效,第二个失败:

var view = new ItemView(100) { PropertySet = new PropertySet { EmailMessageSchema.Id } };
var findResults = ews.FindItems(WellKnownFolderName.Inbox, view)
var bindResults = ews.BindToItems(findResults.Select(r => r.Id), new PropertySet { EmailMessageSchema.Sender });

// Sanity check
Assert.AreEqual(1, bindResults.Count());

// The results I care about
Assert.AreEqual("David Seiler", bindResults[0].Sender.Name);
Assert.AreEqual("[email protected]", bindResults[0].Sender.Address);

有人可能会尝试删除 BindToItems() 调用,并直接使用 FindItems()

var view = new ItemView(100) { PropertySet = new PropertySet { EmailMessageSchema.Sender } };
var findResults = ews.FindItems(WellKnownFolderName.Inbox, view)

// This part still works fine
Assert.AreEqual(1, findResults.Count());

// So does this
Assert.AreEqual("David Seiler", findResults[0].Sender.Name);

// ...but this fails!  Sender.Address is null
Assert.AreEqual("[email protected]", findResults[0].Sender.Address);

谁能告诉我我在哪里?出了问题吗?从文档来看,这似乎确实可行。并非所有属性都可以通过 FindItems() 读取,这是事实,但当我尝试访问这些属性时,这些属性通常会抛出异常,而且无论如何都有一个 MSDN 和 Sender 上这些属性的列表不在上面。这是怎么回事?

After quite a lot of debugging, I've refined a complicated Managed EWS problem down to the following two simple-ish test cases. The first one works, the second one fails:

var view = new ItemView(100) { PropertySet = new PropertySet { EmailMessageSchema.Id } };
var findResults = ews.FindItems(WellKnownFolderName.Inbox, view)
var bindResults = ews.BindToItems(findResults.Select(r => r.Id), new PropertySet { EmailMessageSchema.Sender });

// Sanity check
Assert.AreEqual(1, bindResults.Count());

// The results I care about
Assert.AreEqual("David Seiler", bindResults[0].Sender.Name);
Assert.AreEqual("[email protected]", bindResults[0].Sender.Address);

One might try to cut out the BindToItems() call, and use FindItems() directly:

var view = new ItemView(100) { PropertySet = new PropertySet { EmailMessageSchema.Sender } };
var findResults = ews.FindItems(WellKnownFolderName.Inbox, view)

// This part still works fine
Assert.AreEqual(1, findResults.Count());

// So does this
Assert.AreEqual("David Seiler", findResults[0].Sender.Name);

// ...but this fails!  Sender.Address is null
Assert.AreEqual("[email protected]", findResults[0].Sender.Address);

Can anyone tell me where I've gone wrong? It really seems, from the documentation, as though this should work. Not all properties can be read through FindItems(), it's true, but those properties usually throw when I try to access them, and anyway there's a list of those properties on MSDN and Sender isn't on it. What's going on?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

懒猫 2025-01-03 19:26:35

其实我不知道为什么,但在第二个选项中,它只加载发件人的基本信息,例如姓名,而不是地址。

如果您想加载所有发件人属性但不想绑定完整消息,您可以在第一个断言之前添加以下行

service.LoadPropertiesForItems(findResults.Items, new PropertySet(EmailMessageSchema.Sender));

Actually I don't know why, but in the second option, it only load basic information of the sender like the name, but not the Address.

If you want to load all the sender properties but do not want to bind the full message you can add the following line before the first assert

service.LoadPropertiesForItems(findResults.Items, new PropertySet(EmailMessageSchema.Sender));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文