none
Search for eamil in To field RRS feed

  • Question

  • I am using EWS API 1.1 and would like to search a folder for messages sent to a specific email address.  I can search easily using the following:

    DimfindresultsAsFindItemsResults(OfItem) = myservice.FindItems(WellKnownFolderName.SentItems,NewSearchFilter.ContainsSubstring(itemschema.displayto, strEmailAddress), myiv)

    The problem is that the email address is not always the displayto string.  I tried to replace the itemschema.displayto with emailmessageschema.torecipients, but I get the error "The Property ToRecipients can't be used in FindItem requests". 

    Can someone please point me to a solution to this problem?

    Haim

    Sunday, February 12, 2012 11:30 AM

Answers

  • What version of Exchange are you using that should work okay in 2010 although the property itself wouldn't be returned in a FindItem request. A better method use in 2010 would be to use a AQS query string which will mean the Content Index is used. eg

    DimfindresultsAsFindItemsResults(OfItem) = myservice.FindItems(WellKnownFolderName.SentItems,("System.Message.ToAddress:=" + strEmailAddress), myiv)

    Cheers
    Glen

    • Marked as answer by hik Monday, February 13, 2012 1:28 PM
    Monday, February 13, 2012 3:13 AM

All replies

  • What version of Exchange are you using that should work okay in 2010 although the property itself wouldn't be returned in a FindItem request. A better method use in 2010 would be to use a AQS query string which will mean the Content Index is used. eg

    DimfindresultsAsFindItemsResults(OfItem) = myservice.FindItems(WellKnownFolderName.SentItems,("System.Message.ToAddress:=" + strEmailAddress), myiv)

    Cheers
    Glen

    • Marked as answer by hik Monday, February 13, 2012 1:28 PM
    Monday, February 13, 2012 3:13 AM
  • Thank you Glen.  That worked well, and I never would have been able to figure it out intuitively.  I think my main mistake was in the first line of my code which I didn't post.  The correct code that is working is: 

    myiv.PropertySet = New PropertySet(BasePropertySet.IdOnly, ItemSchema.Subject, _

    ItemSchema.DisplayTo, ItemSchema.DateTimeSent)

    Dimfindresults AsFindItemsResults(OfItem) = myservice.FindItems(WellKnownFolderName.SentItems, _

    "system.Message.ToAddress:="+ strcuremail), myiv)

    Can you point me to a blog or description on how to use the differnt schemas and properties in EWS searches?

    Haim

    Monday, February 13, 2012 1:34 PM
  • Try http://msdn.microsoft.com/en-us/library/hh148195(v=exchg.140).aspx

    If you have any questions just post a followup

    cheers
    Glen
    Tuesday, February 14, 2012 3:46 AM