c# - 使用 c# 与 microsoft exchange 服务建立连接
问题描述
我必须与 Microsoft Exchange Webservice 建立连接,并且我已获得以下详细信息 -
共享邮箱地址是 -
“学生@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>
我在这里的其他线程中寻找相同的内容如何连接到 Exchange?
以及代码项目,但它们都以相同的方式讲述如何连接到交换网络服务。
我不确定为什么我会在 AutodiscoverConfiguration 中获得未经授权的访问,以及我是否使用正确的代码使用已提供的服务帐户信息连接到 Exchange 服务器。
帮助将不胜感激!
TIA
解决方案
您的凭据格式看起来不正确,您应该使用域\用户名或 UPN 的下级格式,请参阅https://msdn.microsoft.com/en-us/library/windows/desktop/aa380525(v= vs.85).aspx。我建议您使用 UPN,因为它应该始终有效。
推荐阅读
- php - 如何使用 lastinsertid() 函数
- android - 使用android约束布局2.0.0 Flow将项目放置一行
- php - 消息:非法字符串偏移量从 Codeigniter2x 版本升级到 Codeigniter 3x 版本
- c++ - 使用 Poco:Condition 唤醒两个线程
- c++ - 如何在安装了 Visual Studio 2017 的 Windows 10 上使用第三方实用程序(包括 swiftshader 和 node 和 node_modules)构建 CEF
- azure - 无法在我使用 Graph API 获得的 Azure AD 应用程序列表中检索我的应用程序之一
- here-api - 匹配路由 API 的 KML 示例
- react-native - 发出一个事件会导致其他事件在本机反应中触发
- transactions - 如何在不完全同步的情况下仅从区块链接收有关特定地址集的交易?
- apache-flink - 如何在不停机的情况下部署新工作