0
votes

I'm working on a task which I never worked in earlier.

Task: Monitor a specific mailbox inbox on exchange server 2007. Iterate through all email messages(Just email messages), do some processing and move to a specific folder under same mailbox.

Work I did

// Create the binding
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
//service.Credentials = new WebCredentials("mailbox", "password", "[email protected]");
service.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["ExchangeUsername"].ToString(), ConfigurationManager.AppSettings["ExchangePassword"].ToString(), "something/domain");
// Set the url.
//service.AutodiscoverUrl("[email protected]");
service.Url = new Uri(ServiceUrl);
ItemView view = new ItemView(10);
view.Traversal = ItemTraversal.Shallow;
view.PropertySet = new PropertySet(BasePropertySet.IdOnly);
List<SearchFilter> searchFilterCollection = new List<SearchFilter>();
//searchFilterCollection.Add(new SearchFilter.ContainsSubstring(ItemSchema.ItemClass, "MessageType"));
searchFilterCollection.Add(new SearchFilter.ContainsSubstring(ItemSchema.Subject, "test to be deleted"));
SearchFilter searchFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.Or, searchFilterCollection.ToArray());

FindItemsResults<Item> results = service.FindItems(WellKnownFolderName.Inbox, view);

For some reason i always get results.items.count = 9, but there is only one EmailMessage in [email protected]. Am i doing any thing wrong in searching. If inbox had 5 emails, then i should get count as 5 and loop through the 5 emails. Is there a way to query just the email messages? Any help is appreciated. Thank you.

1

1 Answers

0
votes

I answered my own questiona a while ago, but forgot to update here. So when i said count was not matching, it was monitoring mailbox of impersonating account. Coincidentally, the impersonating account has a mailbox.