我正在从事一项我之前从未工作过的任务。
任务:监控Exchange Server 2007上的特定邮箱收件箱。迭代所有电子邮件(只是电子邮件),进行一些处理并移至同一邮箱下的特定文件夹。
我做过的工作
// Create the binding
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
//service.Credentials = new WebCredentials("mailbox", "password", "mailbox@something.com");
service.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["ExchangeUsername"].ToString(), ConfigurationManager.AppSettings["ExchangePassword"].ToString(), "something/domain");
// Set the url.
//service.AutodiscoverUrl("mailbox@something.com");
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,但Mailbox@something.com中只有一个EmailMessage。我在搜索中做错了什么。如果收件箱有5封电子邮件,那么我应该算作5并循环浏览5封电子邮件。有没有办法只查询电子邮件?任何帮助表示赞赏。谢谢。
答案 0 :(得分:0)
我刚才回答了自己的问题,但忘了在这里更新。因此,当我说计数不匹配时,它正在监控模拟帐户的邮箱。巧合的是,冒充帐户有一个邮箱。