Exchange Web Service API i 401 nieautoryzowany wyjątek
Gdy próbuję wysłać wiadomość e-mail za pomocą interfejsu API serwera EWS, pojawia się następujący komunikat o błędzie: (wmessage.Send();
)
Żądanie nie powiodło się. Serwer zdalny zwrócił błąd: (401) Nieautoryzowany.
Mój kod jest następujący:
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;
}
Przeczytałem inne posty na tej stronie dotyczące tego problemu, ale nie mogli rozwiązać mojego problemu.