当我尝试使用EWS API发送电子邮件,我得到以下错误:(在message.Send();
)
请求失败。 远程服务器返回错误:(401)未经授权。
我的代码如下:
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;
}
我读了关于这个问题的这个网站的其他职位,但他们解决不了我的问题。