【问题标题】:Connect to Microsoft Exchange Server using C#使用 c# 与 microsoft exchange 服务建立连接
【发布时间】:2018-11-13 23:33:02
【问题描述】:

我必须与 Microsoft Exchange Webservice 建立连接,我已获得以下详细信息 -
共享邮箱地址是说 -

“students@student.edu”

服务帐户是说 -

“学生 SA”

服务帐户的密码是 -

“通过1234”

我遵循了网站https://docs.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> 

我在 How to connect to Exchange? 的其他线程中寻找相同的内容@

还有代码项目,但它们都以相同的方式讲述如何连接到交换网络服务。

我不确定为什么我会在 AutodiscoverConfiguration 中获得未经授权的访问,以及我是否使用提供的服务帐户信息使用正确的代码连接到 Exchange 服务器。

我们将不胜感激!
TIA

【问题讨论】:

标签: c# exchangewebservices service-accounts microsoft-exchange


【解决方案1】:

您的凭据格式看起来不正确,您应该使用域\用户名或 UPN 的下级格式,请参阅https://msdn.microsoft.com/en-us/library/windows/desktop/aa380525(v=vs.85).aspx。我建议您使用 UPN,因为它应该始终有效。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-05
    • 1970-01-01
    • 2019-02-03
    • 1970-01-01
    • 2011-03-28
    • 1970-01-01
    相关资源
    最近更新 更多