c# - EWS:试图找到唯一的文件夹 ID
问题描述
我尝试使用 EWS API 编写解决方案来查找 Outlook 的唯一文件夹 ID。由于某种原因,代码无法正常工作,我无法弄清楚问题出在哪里。我没有使用 EWS API 的经验。
namespace ClassLibrary1
{
public class Class1
{
static void Main(string[] args)
{
// Set server binding
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.UseDefaultCredentials = true;
// Set Credentials
service.Credentials = new WebCredentials("xxxxxxxxx", "xxxxxx");
service.UseDefaultCredentials = true;
// Set the URL
service.AutodiscoverUrl("xxxxx");
// 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);
}
}
}
}
它说未处理异常,autodsicover 阻止了潜在的不安全重定向(..)
解决方案
引发错误时,它提到您需要使用回调来允许重定向。沿线的东西
service.AutodiscoverUrl("xxxxx", ValidateRedirectionUrlCallback);
...
private static bool ValidateRedirectionUrlCallback(string url)
{
// Validate the URL and return true to allow the redirection or false to prevent it.
return true; //allow redirections
}
推荐阅读
- javascript - 基于 OR 表达式的变量赋值的简写
- c - C char 数组和 \0
- typescript - 后续的属性声明必须具有相同的类型
- c# - C# 类到带有 ID 的 json 模式
- apache-spark - 带有 Kotlin 和 Apache Spark 2.3 的胖 JAR
- objective-c - 回调强引用循环
- java - 将外部声明的 bean 标记为 @Primary
- git - hoek 节点模块的 Github 潜在安全漏洞错误
- ios - 具有不同图像尺寸并保持图像纵横比的布局
- python - AttributeError:“_mysql.connection”对象没有属性“光标”