我必须建立与Microsoft Exchange Webservice的连接,我已获得以下详细信息-
共享邮箱地址是这样说的-
"students@student.edu“
服务帐户是这样的-
“学生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>
我在这里的其他帖子中寻找了同样的东西How to connect to Exchange?
在Code项目上也是如此,但它们都以相同的方式告诉我们如何连接到exchange webservice。
我不确定为什么我在AutodiscoverConfiguration中得到未经授权的访问,也不确定我是否使用正确的代码使用已提供的服务帐户信息连接到exchange服务器。
我们将非常感谢您的帮助!
提亚
发布于 2018-06-05 07:19:56
您的凭据格式看起来不正确,您应该使用下层格式,即domain\username或UPN,请参阅https://msdn.microsoft.com/en-us/library/windows/desktop/aa380525(v=vs.85).aspx。我建议您使用UPN,因为它应该总是有效的。
https://stackoverflow.com/questions/50683838
复制相似问题