尝试在 EWS C# 中查找文件夹的唯一 ID API

Trying to find unique id of folder in EWS C# API

我正在尝试在 Outlook 中查找文件夹的唯一 ID。

出于某种原因,我一直在使用 AutoDiscoverUrl 方法时出错,但我不知道为什么。我已经在 Whosebug 上尝试了所有可能的解决方案。

我正在尝试使用 C# 在命令行程序中 运行 它,并有 commented/documented 代码。我已经使用了其他人的示例来说明如何执行此操作,但它不起作用。

static void Main(string[] args)
{
    // Set server binding
    ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
    service.UseDefaultCredentials = true;

    // Set Credentials
    service.Credentials = new WebCredentials("xxxx", "xxxxx", "xxxx");
    service.UseDefaultCredentials = true;

    service.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");

    // Set the URL 
    service.AutodiscoverUrl("xxxx", Callback);

    // Error Tracing
    service.TraceEnabled = true;

    // Redirect callback

    // Set View
    FolderView view = new FolderView(100);
    view.PropertySet = new PropertySet(BasePropertySet.IdOnly);
    view.PropertySet.Add(FolderSchema.DisplayName);
    view.Traversal = FolderTraversal.Deep;

    FindFoldersResults findFolderResults = service.FindFolders(WellKnownFolderName.Root, view);

    // Find specific folder
    foreach (Folder f in findFolderResults)
    {
        // Show FolderId of the folder "test"
        if (f.DisplayName == "test")
        {
            Console.WriteLine(f.Id);
        }
    }
}

private static bool Callback(string redirectionUrl)
{
    bool result = false;
    var redirectionUri = new Uri(redirectionUrl);
    if (redirectionUri.Scheme == "https")
    {
        result = true;
    }
    return result;
}

您可以使用以下代码找到文件夹的唯一 ID:

ExchangeService Service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
Service.UseDefaultCredentials = false;
Service.Credentials = new WebCredentials("yourUserID", "yourPassword");

Mailbox ProdSupportMailbox = new Mailbox("ProdSupport@company.com");
Service.AutodiscoverUrl("ProdSupport@company.com");

FolderView view = new FolderView(100);
view.PropertySet = new PropertySet(BasePropertySet.IdOnly);
view.PropertySet.Add(FolderSchema.DisplayName);
view.Traversal = FolderTraversal.Deep;

FindFoldersResults findFolderResults = server.FindFolders(WellKnownFolderName.Root, view);

// find specific folder
foreach(Folder f in findFolderResults)
{
    // show folderId of the folder "Test"
    if (f.DisplayName == "Test")
    {
        Console.WriteLine(f.Id);
    }
}

更多信息,请参考以下链接:

Exchange Web Service FolderId for a not well known folder name

Microsoft Exchange Web Services reading my local Outlook folders INSTEAD of another address