OfficeDev / ews-managed-api

Other
583 stars 317 forks source link

401 unauthorized exception because of special char in password? #302

Open maslewandowski opened 1 year ago

maslewandowski commented 1 year ago

I'm trying to get access to an exchange 2016 server using EWS in a .net 7 console application. There seems to be problem with one account and I already investigated much time on research but I can't fix this.

The password contains two "special" characters. For security reasons let me reduce the password to those two characters:

string password = "\"";

This code works properly with all other accs of the domain, except the one with the above mentioned password:

_exchangeService = new ExchangeService();
_exchangeService.TraceEnabled = true;
_exchangeService.TraceFlags = TraceFlags.All;
_exchangeService.Credentials = new WebCredentials(_sender, DecryptPassword(), "domain");
_exchangeService.Url = new Uri(_mailServerAdress);
_exchangeService.UseDefaultCredentials = false;

var message = new EmailMessage(_exchangeService);
message.Subject = "Test";
message.Body = "Test";
message.ToRecipients.Add(recipient);
message.SendAndSaveCopy();

Am I missing something here?