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封電子郵件循環。有沒有辦法查詢電子郵件?任何幫助表示讚賞。謝謝。