我們希望能夠從包含在我們的Exchange服務器的所有郵箱獲得封未讀郵件的主郵箱的多個郵箱。從那裏,我們將在我們的應用程序中處理它們,然後刪除它們。未讀郵件的數量將一直很小。獲得使用EWS
我們的第一個想法是創建一個主郵箱,給他充分的訪問(EPS)到其他郵箱,並與EWS獲得未讀郵件。我們試過這個:
//Define the service
ExchangeService service = new ExchangeService(SERVICE_VERSION);
service.Url = new Uri(SERVICE_URL);
service.Credentials = new WebCredentials("MyAdmin", "MyPassword");
//define our search
FolderView viewFolders = new FolderView(int.MaxValue) { Traversal = FolderTraversal.Deep, PropertySet = new PropertySet(BasePropertySet.IdOnly) };
ItemView viewEmails = new ItemView(int.MaxValue) { PropertySet = new PropertySet(BasePropertySet.IdOnly) };
SearchFilter unreadFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false));
//search all items in Inbox and subfolders
FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Root, unreadFilter, viewEmails);
//bind the result
ServiceResponseCollection<GetItemResponse> responseList =
service.BindToItems(findResults.Select(item => item.Id), new PropertySet(BasePropertySet.FirstClassProperties,EmailMessageSchema.ReceivedBy, EmailMessageSchema.From, EmailMessageSchema.Subject, EmailMessageSchema.Attachments));
但是,這隻會從MyAdmin郵箱得到未讀郵件。通過進一步調查,我們發現這種方式從另一個特定郵箱獲取未讀郵件:
//Define the service
ExchangeService service = new ExchangeService(SERVICE_VERSION);
service.Url = new Uri(SERVICE_URL);
service.Credentials = new WebCredentials("MyAdmin", "MyPassword");
//define our search
FolderView viewFolders = new FolderView(int.MaxValue) { Traversal = FolderTraversal.Deep, PropertySet = new PropertySet(BasePropertySet.IdOnly) };
ItemView viewEmails = new ItemView(int.MaxValue) { PropertySet = new PropertySet(BasePropertySet.IdOnly) };
SearchFilter unreadFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false));
//define the user mailbox
var userMailbox = new Mailbox("[email protected]");
var folderId = new FolderId(WellKnownFolderName.Inbox, userMailbox);
//search all items in Inbox
var userItems = service.FindItems(folderId, unreadFilter, viewEmails);
這種解決方案的問題是3000個郵箱,我們必須再查詢3000次EWS從每個郵箱中獲取未讀郵件(知道很多人不會有未讀的郵件)。
有沒有一種方法來獲得,在單呼,從Exchange服務器的每個郵箱中的所有封未讀郵件?我們正在使用Exchange 2013和最新的EWS。
在此先感謝
我不認爲它是可能的。我認爲你必須爲每個用戶提供服務。 SO中有按鈕,我想繼續觀看。上投了反對票。 – Seabizkit
這裏是如何關注SO中的問題。感謝您的支持。 http://meta.stackexchange.com/questions/86877/how-to-follow-a-question-on-stackoverflow –
可以使用電子發現做多郵箱搜索https://msdn.microsoft.com/en- us/library/office/jj190897(v = exchg.150).aspx但是IsRead沒有被索引,所以它不是你可以做的查詢,所以你唯一的選擇是做3000個請求。 –