使用C#连接到Microsoft Exchange Server

3
我需要与Microsoft Exchange Webservice建立连接,并且我已经获得了以下细节 - 共享邮箱地址为:

"students@student.edu"

服务账户是:

"Student SA"

服务账户密码为:

"Pass1234"

我按照网站上给出的代码示例进行操作:

https://learn.microsoft.com/en-us/exchange/client-developer/exchange-web-services/get-started-with-ews-managed-api-client-applications

下面是使用上述细节的代码示例 -

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 服务器。


你尝试过使用https://testconnectivity.microsoft.com来验证AutoDiscover是否适用于该帐户? - tjhazel
你修好了吗?如果是的话,能否请您分享一下您是如何修复它的细节? - Ash K
2个回答

0

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接