交易所Web服务API和401未授权异常 [英] Exchange Web Service API and 401 unauthorized exception

查看:918
本文介绍了交易所Web服务API和401未授权异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用EWS API发送电子邮件,我得到以下错误:(在 message.Send();

When I try sending email using the EWS API, I get the following error: (in message.Send();)

请求失败。远程服务器返回错误:(401)未经授权

The request failed. The remote server returned an error: (401) Unauthorized.

我的code是以下内容:

My code is the following:

ExchangeService exchangeService = new ExchangeService(ExchangeVersion.Exchange2007_SP1);

//WebService Uri
try
{
    exchangeService.Url = new Uri("https://exchangeserver/ews/exchange.asmx");
}
catch (Exception ex)
{
    throw new Exception(string.Format("WebService Uri:" + ex));
}

//Credentials
try
{
    exchangeService.Credentials = new WebCredentials("user@domain", "pwd", "domain");
}
catch (Exception ex)
{
    throw new Exception(string.Format("Credentials:" +  ex));
}

//Send a mail
try
{
    EmailMessage message = new EmailMessage(exchangeService);
    message.Subject = "Test";
    message.Body = "Test";
    message.ToRecipients.Add("destination@domain");
    message.Save();
    message.Send();
}
catch (Exception ex)
{
    throw ex;
}

我读了这个网站有关这一问题的其他职位,但他们解决不了我的问题。

I read other posts on this site concerning this issue but they couldn't resolve my issue.

推荐答案

尝试改变这一点:

 exchangeService.Credentials = new WebCredentials("user@domain", "pwd", "domain");

这个:

 exchangeService.Credentials = new WebCredentials("user", "pwd", "domain");

有时登录凭据依赖于交换/ Active Directory的它是如何的配置。
这可能是用户@域或域\\用户

Sometime the Login credentials depends on how Exchange/Active Directory it's configured. It could be user@domain or domain\user

这篇关于交易所Web服务API和401未授权异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆