,當我嘗試使用EWS API發送電子郵件,我得到以下錯誤:(在message.Send();
)的Exchange Web服務API和401未授權異常
The request failed. The remote server returned an error: (401) Unauthorized.
我的代碼如下:
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("[email protected]", "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("[email protected]");
message.Save();
message.Send();
}
catch (Exception ex)
{
throw ex;
}
我閱讀了本網站上關於此問題的其他帖子,但他們無法解決我的問題。
你通過問這個問題拯救了我的職業生涯! – Chookoos
我的榮幸:)! – GwenGuts
在以前EWS連接正常工作但不起作用的情況下,它可能與密碼過期一樣簡單,需要更改。 – RenniePet