首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用c#建立与microsoft exchange service的连接

使用c#建立与microsoft exchange service的连接
EN

Stack Overflow用户
提问于 2018-06-04 23:19:19
回答 1查看 1.2K关注 0票数 2

我必须建立与Microsoft Exchange Webservice的连接,我已获得以下详细信息-

共享邮箱地址是这样说的-

"students@student.edu“

服务帐户是这样的-

“学生SA”

服务帐户的密码是-

"Pass1234“

我遵循了网站https://docs.microsoft.com/en-us/exchange/client-developer/exchange-web-services/get-started-with-ews-managed-api-client-applications中给出的代码示例

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

代码语言:javascript
复制
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;
        }

当我在本地运行它时,我得到下面的错误消息

代码语言:javascript
复制
    <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服务器。

我们将非常感谢您的帮助!

提亚

EN

回答 1

Stack Overflow用户

发布于 2018-06-05 07:19:56

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50683838

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档