When you used AutodiscoverUrl () with RedirectionUrlValidationCallback, here is a sample code:
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1); service.PreAuthenticate = true; service.Credentials = new WebCredentials("my_username","my_password"); //use WebCredentials instead of NetworkCredential service.AutodiscoverUrl(userEmailAddress, RedirectionCallback);
And the RedirectionCallback method should be like this:
static bool RedirectionCallback(string url) { bool redirectionValidated = false; Uri redirectionUri = new Uri(url); //There are two ways of implementing a RedirectionCallback scheme // Way 1: Return true if the URL is an HTTPS URL. //return url.ToLower().StartsWith("https://"); if (redirectionUri.Scheme == "https") redirectionValidated = true; //Way 2: check if url is autodiscovery url if (url.Equals( "https://autodiscover-s.outlook.com/autodiscover/autodiscover.xml")) redirectionValidated = true; return redirectionValidated; }
PS: Take care of proxies that prohibit the Autodiscover service. In my case, this code returned the error "Autodiscover service cannot be found" every time, but the main reason was 403 Forbidden when calling autodiscover. This works after setting up the proxy.
Jyotsana nandwani
source share