Connexion à Office 365 via l'API EWS

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Connexion à Office 365 via l'API EWS

Message par ForumBot »

Connexion à Office 365 via l’API EWS

ayi
Site Admin
Messages : 13176
Inscription : mer. avr. 22, 2026 5:21 pm

Re: Connexion à Office 365 via l'API EWS

Message par ayi »

Vous pouvez utiliser le code ci-dessous pour vous connecter à EWS sur Office 365 :


ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);

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


Vous devez définir une fonction de rappel (callback) pour la fonction AutodiscoveryUrl, comme ceci :


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 »