none
[Exchange-Online][EWS][C#][Windows 7] Move email based on their categories RRS feed

  • Question

  • Hello,

    I'd like to move emails in the Inbox to a separate folder based on their category.

    I'm using Microsoft.Exchange.WebServices (15.0.0.0) to connect to an ExchangeVersion.Exchange2013_SP1 instance. I'm using C# in VS2013 and the .NET 4 framework but can take examples from other versions if they exist.

    I've tried using SearchFilter without much success through ExchangeService.FindItems, but the 'Categories' property seems to be tricky to configure.

    Does anyone have an example of how I can select/move emails from a folder based on their category membership?

    Thanks,

    Mike

    Tuesday, July 22, 2014 10:47 AM

Answers

  • It should work okay what matters is what's stored in the Keywords property eg

    The only other thing that would be important would be that Indexing is working okay in Exchange as this query relies on the Indexes (eg check your event logs on the server to make sure you not getting any indexing errors).

    One thing you can do to test this is use the EWSEditor http://ewseditor.codeplex.com/once you have connected right click the folder when the Items are located and select Search from the menu. Then using the AQS option try running some queries against the folder try the Conical version(which is what I gave you) and the non conical Category:Clare . If it works okay in the EWSEditor but not in your code then you have an issue somewhere else in your code. I would also do the simple thingss like try then with a new message you send yourself as it maybe something to do with Items not being indexed in the past etc.

    Cheers
    Glen

    Wednesday, July 30, 2014 4:20 AM

All replies

  • The Categories Property is a Multivalued String so using a SearchFiter isn't the best way to do that, on 2010 and 2013 this property is indexed so you can use AQS and a QueryString instead eg

                ItemView iv = new ItemView(1000);
                String AQS = "System.Category:red OR System.Category:green";
                FindItemsResults<Item> fiItems = null;
                do
                {
                    fiItems = service.FindItems(WellKnownFolderName.Inbox, AQS, iv);
                    foreach (Item itItem in fiItems.Items)
                    {
                        Console.WriteLine(itItem.Subject);
                    }
                    iv.Offset += fiItems.Items.Count;
                } while (fiItems.MoreAvailable == true);
    Cheers
    Glen

     
    Wednesday, July 23, 2014 6:27 AM
  • Glen,

    Sounds good but it's not working for me. I've copied your example to my project but have replaced your line

    String AQS = "System.Category:red OR System.Category:green";

    with

    String AQS = "System.Category:Clare";

    The result of running this against my folder containing one email which has been flagged with the category named "Clare" is that filItems.Count = 0. I thought this might be because I wasn't using the standard category names, but changing the category on the email to 'Orange Category' and the string to

    String AQS = "System.Category:Orange";
    still returns no items. Any idea's what I'm doing wrong?
    Tuesday, July 29, 2014 9:28 AM
  • It should work okay what matters is what's stored in the Keywords property eg

    The only other thing that would be important would be that Indexing is working okay in Exchange as this query relies on the Indexes (eg check your event logs on the server to make sure you not getting any indexing errors).

    One thing you can do to test this is use the EWSEditor http://ewseditor.codeplex.com/once you have connected right click the folder when the Items are located and select Search from the menu. Then using the AQS option try running some queries against the folder try the Conical version(which is what I gave you) and the non conical Category:Clare . If it works okay in the EWSEditor but not in your code then you have an issue somewhere else in your code. I would also do the simple thingss like try then with a new message you send yourself as it maybe something to do with Items not being indexed in the past etc.

    Cheers
    Glen

    Wednesday, July 30, 2014 4:20 AM
  • Thanks Glen.

    I think it works now.

    Mike

    Tuesday, August 12, 2014 9:04 AM