【发布时间】:2018-11-13 23:33:02
【问题描述】:
我必须与 Microsoft Exchange Webservice 建立连接,我已获得以下详细信息 -
共享邮箱地址是说 -
“students@student.edu”
服务帐户是说 -
“学生 SA”
服务帐户的密码是 -
“通过1234”
下面是我使用上述细节的代码示例 -
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>
我在 How to connect to Exchange? 的其他线程中寻找相同的内容@
还有代码项目,但它们都以相同的方式讲述如何连接到交换网络服务。
我不确定为什么我会在 AutodiscoverConfiguration 中获得未经授权的访问,以及我是否使用提供的服务帐户信息使用正确的代码连接到 Exchange 服务器。
我们将不胜感激!
TIA
【问题讨论】:
-
您是否尝试过https://testconnectivity.microsoft.com 来验证该帐户的自动发现功能?
标签: c# exchangewebservices service-accounts microsoft-exchange