我需要与Microsoft Exchange Webservice建立连接,并且我已经获得了以下细节 - 共享邮箱地址为:
当我在本地运行时,出现以下错误信息:
"students@student.edu"
服务账户是:
"Student SA"
服务账户密码为:
"Pass1234"
我按照网站上给出的代码示例进行操作:
下面是使用上述细节的代码示例 -
static void Main(string[] args)
{
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
service.Credentials = new WebCredentials("Student SA", "Pass1234");
service.TraceEnabled = true;
service.TraceFlags = TraceFlags.All;
service.AutodiscoverUrl("students@student.edu", RedirectionUrlValidationCallback);
// service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.PrincipalName, "myADAccount");
}
private static bool RedirectionUrlValidationCallback(string redirectionUrl)
{
// The default for the validation callback is to reject the URL.
bool result = false;
Uri redirectionUri = new Uri(redirectionUrl);
// Validate the contents of the redirection URL. In this simple validation
// callback, the redirection URL is considered valid if it is using HTTPS
// to encrypt the authentication credentials.
if (redirectionUri.Scheme == "https")
{
result = true;
}
return result;
}
当我在本地运行时,出现以下错误信息:
<Trace Tag="AutodiscoverConfiguration" Tid="9" Time="2018-06-04 15:10:07Z">
Request error: The remote server returned an error: (401) Unauthorized.
</Trace>
我在其他帖子里查找了相关信息
并且在 Code Project 上也找到了类似的内容,但它们都是关于如何连接到 Exchange WebService 的。
我不确定为什么在自动发现
配置中出现了未授权访问的问题,也不确定我是否使用了正确的代码来使用提供的服务帐户信息连接到 Exchange 服务器。