Search code examples
exchangewebservicesimpersonationews-managed-api

EWS Impersonation Error "The e-mail address that was supplied isn't valid." Although It Is


Exchange 2010 (SP3) Impersonation is properly configured, according to the sys admin.

The issue seems to be with code:

private static ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
//service.Credentials = new NetworkCredential(user,password,domain) OK
//service.AutodiscoverUrl OK
...
service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress,usrEmail);
//create a contact and try to save it in a particular contacts subfolder
contact.Save(subfolder.Id);

this is where it blows with the error "The e-mail address that was supplied isn't valid." This really doesn't make sense to me, because I supplied my email address which I know 100% that is valid.

I tried googling this and I don't feel lucky at all.

P.S. I tried various impersonation scenarios with ConnectingIdType.SmtpAddress and ConnectingIdType.PrincipalName, no difference.

Any idea how to fix this? Many thanks, in advance.


Solution

  • Is the error for impersonation or for the Contact your trying to save? That error relates to ErrorInvalidContactEmailAddress which usually means it relates to the Contact your trying to save not the user your impersonating. Easy way to test this would be to bind the Contact Folder using impersonation, for example:

    ContactsFolder Contacts = ContactsFolder.Bind(service, WellKnownFolderName.Contacts);
    

    If that works okay then you know its data validation error with the contact your trying to save.