방금 교환 된 Web Services Managed API를 발견했습니다. 제가 해왔 던 문제에 대한 해결책을 제공 할 수 있다고 생각하기 때문에이 API를 사용하여 이해하려고 노력했습니다.Exchange Web Services Managed API를 사용하여 해당 폴더에있는 모든 폴더 및 파일을 나열하는 방법?
배경
나는 많은 문서를 읽고 사물의 일반적인 의미를했습니다. 특히, 나는 LINK과 매우 비슷한 것을 설정했다.
그러나 폴더를 표시 한 다음 폴더 뒤에 관련된 모든 EmailMessage 항목을 표시하는 등 모든 폴더/하위 폴더를 통해 원하는대로 표시하고 싶습니다. 지금까지 작성한 코드는 폴더를 나열하지만 폴더와 관련된 전자 메일 대신 반환 한 모든 전자 메일을 나열합니다. 나는 목록을 작게 유지하기 위해 읽지 않은 항목을 찾고 있습니다.
코드 문제의
private static void GetAllItems(ExchangeService service)
{
List<Folder> lstFolderIds = new List<Folder>();
// Fill list with all public folders and sub-folders
GetAllFolders(service, lstFolderIds);
List<EmailMessage> emails = new List<EmailMessage>();
foreach(Folder folder in lstFolderIds)
{
SearchFilter sf = new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false));
ItemView view = new ItemView(int.MaxValue);
view.PropertySet = PropertySet.IdOnly;
FindItemsResults<Item> searchResults = service.FindItems(folder.Id, sf, view);
if (searchResults.Items.Count > 0)
{
foreach (var item in searchResults.Items)
{
try
{
if (item is EmailMessage)
{
emails.Add((EmailMessage)item);
}
}
catch (Exception ex)
{
Console.WriteLine("Exception: {0}", ex.Message);
Console.WriteLine("Stack Trace: {0}", ex.StackTrace);
Console.WriteLine("Source: {0}", ex.Source);
Console.WriteLine("HResult: {0}", ex.HResult);
}
}
}
}
PropertySet properties = (BasePropertySet.FirstClassProperties);
service.LoadPropertiesForItems(emails, properties);
foreach (Folder folder in lstFolderIds)
{
object folderName;
object displayName;
object childFolderCount;
object unreadCount;
object totalCount;
folderName = folder.TryGetProperty(FolderSchema.ParentFolderId, out folderName) ? folder.ParentFolderId.FolderName.Value.ToString() : "N/A";
displayName = folder.TryGetProperty(FolderSchema.DisplayName, out displayName) ? folder.DisplayName.ToString() : "N/A";
childFolderCount = folder.TryGetProperty(FolderSchema.ChildFolderCount, out childFolderCount) ? folder.ChildFolderCount.ToString() : "N/A";
unreadCount = folder.TryGetProperty(FolderSchema.UnreadCount, out unreadCount) ? folder.UnreadCount.ToString() : "N/A";
totalCount = folder.TryGetProperty(FolderSchema.TotalCount, out totalCount) ? folder.TotalCount.ToString() : "N/A";
Console.WriteLine("Parent Folder: {0}", folderName);
Console.WriteLine("Folder Display Name: {0}", displayName);
Console.WriteLine("Child Folder Count: {0}", childFolderCount);
Console.WriteLine("Folder Unread Count: {0}", unreadCount);
Console.WriteLine("Folder Total Count: {0}", totalCount);
Console.WriteLine("---------------------------------------------------------");
foreach (EmailMessage email in emails)
{
object parentFolderName;
object subject;
object retentionDate;
parentFolderName = email.TryGetProperty(EmailMessageSchema.ParentFolderId, out parentFolderName) ? email.ParentFolderId.FolderName.Value.ToString() : "N/A";
subject = email.TryGetProperty(EmailMessageSchema.Subject, out subject) ? email.Subject.ToString() : "N/A";
retentionDate = email.TryGetProperty(EmailMessageSchema.RetentionDate, out retentionDate) ? retentionDate.ToString() : "N/A";
Console.WriteLine("\tParent Folder Name: {0}", parentFolderName);
Console.WriteLine("\tSubject: {0}", subject);
Console.WriteLine("\tRetention Date: {0}", retentionDate);
//}
}
Console.WriteLine("");
Console.WriteLine("Press or select Enter...");
Console.Read();
}
}
일부는 내가 폴더 또는 EmailMessage의 부모 폴더 이름의 폴더 이름을 얻는 방법을 알아낼 수 있다는 것입니다. 폴더에 대한 폴더 ID와 EmailMessage에 대한 상위 폴더 ID를 얻을 수 있지만 반환 된 모든 항목에 대해 동일하므로 옳지 않아야합니다.
나는이 LINK에서 폴더를 EmailMessage 항목과 관련시키기 위해 추가 바인딩을 수행해야한다고 읽었지 만, 그 방법을 정확히 모르겠습니다.
예상 출력
Parent Folder:
Folder Display Name: Inbox
Child Folder Count: 1
Folder Unread Count: 2
Folder Total Count: 51
---------------------------------------------------------
Parent Folder Name: Inbox
Subject: New Coversheets for TPS Reports
Retention Date: 10/31/2017 11:59:59 PM
Parent Folder Name: Inbox
Subject: Have you seen my stapler?
Retention Date: 07/31/2017 11:59:59 PM
Parent Folder:
Folder Display Name: Sent Items
Child Folder Count: 0
Folder Unread Count: 0
Folder Total Count: 27
---------------------------------------------------------
No Un-Read Items
질문
- 어떻게 내 검색 조건에 일치 관련 EmailMessages있는 폴더 계층 구조를 나열합니까?
- 현재 MsgFolderRoot의 Id를 얻고있는 FolderId/ParentFolderId가 있습니까? 아니면 말할 방법이 있습니까?
- 어떻게 Folder.FolderId.FolderName.Value 및 EmailMessage.ParentFolderId.FolderName.Value를 얻습니까?
- # 2에 바인딩이 필요한 경우 누구나 공유 할 수있는 예제 또는 링크가 있습니까?
업데이트 (들) 질문하기 전에 예상 출력
- 추가 된 섹션.
감사합니다.