FindItems()和BindToItems()给出的EmailMessage.Sender.Address结果不一致 [英] FindItems() and BindToItems() give inconsistent results for EmailMessage.Sender.Address

查看:133
本文介绍了FindItems()和BindToItems()给出的EmailMessage.Sender.Address结果不一致的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经过大量的调试,我将复杂的Managed 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("david.seiler@yahoo.com", 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("david.seiler@yahoo.com", findResults[0].Sender.Address);

谁能告诉我我哪里出问题了?从文档看来,这似乎确实可行.并非所有属性都可以通过FindItems()读取,这是事实,但是当我尝试访问它们时,这些属性通常会抛出,并且总有一个解决方案

实际上我不知道为什么,但是在第二种选择中,它仅加载发件人的基本信息,例如姓名,而不是地址. >

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

service.LoadPropertiesForItems(findResults.Items, new PropertySet(EmailMessageSchema.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("david.seiler@yahoo.com", 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("david.seiler@yahoo.com", 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?

解决方案

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));

这篇关于FindItems()和BindToItems()给出的EmailMessage.Sender.Address结果不一致的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆