FindItems() and BindToItems() give inconsistent results for EmailMessage.Sender.Address

亡梦爱人 提交于 2019-12-23 20:13:21

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/8904741/finditems-and-bindtoitems-give-inconsistent-results-for-emailmessage-sender

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!