EWS Office 365 Impersonation not working

3.5k views Asked by At

I'm connecting to our office 365 account and trying to send an email.

My connection to office 365 :

var exchangeService = new ExchangeService(ExchangeVersion.Exchange2013_SP1)
{
    Credentials = new WebCredentials([email protected], MyPassword),
    Url = new Uri(url),
    ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, [email protected])
};

If I remove the ImpersonatedUserId section, the email sends ok.

However if I set the ImpersonatedUserId, I keep getting the following error "The account does not have permission to impersonate the requested user."

I have tried setting the type to ConnectingIdType.PrincipalName but that does not work either.

I would like to eventually send emails on behalf of other people but at the moment I am testing this with my own account.

I'm using the same email address for both the credentials and the Impersonation, so I am stuck why it will not send?

1

There are 1 answers

0
user2859298 On

The code above works fine, the issue is with Office 365 Exchange.

Even if you are sending through your own account you have to have the Impersonation role set.

Please see the following URL : http://www.codetwo.com/kb/how-to-set-impersonation-rights-manually/