2011-06-20 64 views
0

我正在處理一個我從未在之前工作過的任務。使用EWS託管API監視郵箱中的新電子郵件

任務:監視交換服務器2007上的特定郵箱收件箱。遍歷所有電子郵件(只是電子郵件消息),做一些處理並移動到同一郵箱下的特定文件夾。

工作我做了

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

出於某種原因,我總是得到results.items.count = 9,但只能有一個EmailMessage在[email protected]。我在做任何錯誤的搜索。如果收件箱中有5封電子郵件,那麼我應該算作5並通過5封電子郵件循環。有沒有辦法查詢電子郵件?任何幫助表示讚賞。謝謝。

回答

0

前段時間我回答了我自己的問題,但忘了在這裏更新。所以當我說計數不匹配時,它正在監視模擬賬戶的郵箱。巧合的是,冒充帳戶有一個郵箱。

相關問題