searching Exchange mailbox by email address using SearchFilterCollection

。_饼干妹妹 提交于 2019-12-13 04:42:37

问题


I am searching an email inbox (on Exchange 2010) using Exchange Web Services.

In my SearchFilterCollection I would like to include the From.Address property of the Email message, as I only want to retrieve emails that include a certain domain (such as @domain.co.uk)

here is my code:

SearchFilter.SearchFilterCollection searchFilterCollection = new SearchFilter.SearchFilterCollection(LogicalOperator.And);
searchFilterCollection.Add(new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false));
searchFilterCollection.Add(new SearchFilter.IsEqualTo(EmailMessageSchema.HasAttachments, true));

// **** PROBLEM HERE ON BELOW LINE****       
searchFilterCollection.Add(new SearchFilter.ContainsSubstring(EmailMessageSchema.From, "@domain.co.uk")); // 

// add the exceptions
for (int iEx = 0; iEx < e2c.emailExceptions.Count; iEx++)
    {
    searchFilterCollection.Add(new SearchFilter.Not(new SearchFilter.ContainsSubstring(EmailMessageSchema.Subject, e2c.emailExceptions[iEx])));
    }

    ItemView view = new ItemView(100);
    view.OrderBy.Add(ItemSchema.DateTimeReceived, SortDirection.Ascending);

    // Find the first email message in the Inbox that has attachments. This results in a FindItem operation call to EWS.
    FindItemsResults<Item> results = service.FindItems(WellKnownFolderName.Inbox, searchFilterCollection, view);

is there a good way to include the email address in the SearchFilter?


回答1:


I just created a search folder the other day that did the same thing, using the example from the How to: Work with search folders by using EWS in Exchange topic:

// Create a search filter to express the criteria
// for the folder.
EmailAddress manager = new EmailAddress("sadie@contoso.com");

SearchFilter.IsEqualTo fromManagerFilter =
    new SearchFilter.IsEqualTo(EmailMessageSchema.Sender, manager);

Now this is using the Sender property, not the From property. I think you could simply replace one for the other, but I didn't test to be sure.



来源:https://stackoverflow.com/questions/22991782/searching-exchange-mailbox-by-email-address-using-searchfiltercollection

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