Connection to Office 365 by EWS API

Clippy
Messages : 22157
Inscription : mer. 22 avr. 2026, 17:33

Connection to Office 365 by EWS API

Message par Clippy »

Connection to Office 365 by EWS API
Clippy
Messages : 22157
Inscription : mer. 22 avr. 2026, 17:33

Re: Connection to Office 365 by EWS API

Message par Clippy »

You can use the code below to connect to the EWS on office 365:

```
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);

service.Credentials = new WebCredentials("[email protected]", "password");
service.AutodiscoverUrl("[email protected]", RedirectionUrlValidationCallback);

```

You need define one callback function for the AutodiscoveryUrl function, like this:

```
private static bool RedirectionUrlValidationCallback(string redirectionUrl)
{
// The default for the validation callback is to reject the URL.
bool result = false;

Uri redirectionUri = new Uri(redirectionUrl);

// Validate the contents of the redirection URL. In this simple validation
// callback, the redirection URL is considered valid if it is using HTTPS
// to encrypt the authentication credentials.
if (redirectionUri.Scheme == "https")
{
result = true;
}
return result;
}

```
Répondre

Revenir à « Excel & VBA »