Jak mogę połączyć się z serwerem wymiany i czytać pocztę ze wspólnej skrzynki pocztowej (takiej, która nie jest moją własną "[email protected]").C# EWS Managed API: jak uzyskać dostęp do współdzielonych skrzynek pocztowych, ale nie do mojej własnej skrzynki odbiorczej.
Oto mój kod do tej pory:
//Create a service
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
//Autodiscover end point
service.AutodiscoverUrl("someaddr[email protected]");
FindFoldersResults folderSearchResults = service.FindFolders(WellKnownFolderName.Inbox, new FolderView(int.MaxValue));
Microsoft.Exchange.WebServices.Data.Folder exchangeMailbox = folderSearchResults.Folders.ToList().Find(
f => f.DisplayName.Equals("NameOfSharedMailboxIwant", StringComparison.CurrentCultureIgnoreCase));
//Set the number of items we can deal with at anyone time.
ItemView itemView = new ItemView(int.MaxValue);
foreach (Microsoft.Exchange.WebServices.Data.Folder folderFromSearchResults in folderSearchResults.Folders)
{
if (folderFromSearchResults.DisplayName.Equals("NameOfSharedMailboxIWant", StringComparison.OrdinalIgnoreCase))
{
Microsoft.Exchange.WebServices.Data.Folder boundFolder =
Microsoft.Exchange.WebServices.Data.Folder.Bind(service, folderFromSearchResults.Id);
SearchFilter unreadSearchFilter =
new SearchFilter.SearchFilterCollection(
LogicalOperator.And, new SearchFilter.IsEqualTo(
EmailMessageSchema.IsRead, false));
//Find the unread messages in the email folder.
FindItemsResults<Item> unreadMessages = boundFolder.FindItems(unreadSearchFilter, itemView);
foreach (EmailMessage message in unreadMessages)
{
message.Load();
Console.WriteLine(message.Subject);
}
}
Kiedy uruchamiam to uzyskać wyjątek rzucony, który mówi, że „adres SMTP nie ma skrzynki pocztowej z nim związane” w czasie:
Microsoft.Exchange.WebServices.Data.Folder exchangeMailbox = folderSearchResults.Folders.ToList().Find(
f => f.DisplayName.Equals("BA", StringComparison.CurrentCultureIgnoreCase));
Czego mi brakuje? Czuję, że już prawie jestem i że to powinno działać zgodnie z dokumentacją EWS Managed API 2.0, ale I
Czy istnieje sposób wyliczyć wszystkich udostępnionych skrzynek jesteś częścią? – Alexandru
Opublikowaliśmy tutaj dodatkowe pytanie: http://stackoverflow.com/questions/38881919/enumerating-shared-mailbox-names-you-able-able-to-access-ews-managed-api – Alexandru
odpowiedź nie jest odpowiednia dla żadnej dobrze znanej nazwy folderu. – Myzifer