Reputation: 69
While analyzing a program I saw a function called AutoDiscoverURL !! I have googled it, unfortunately not able to figure it out.
Upvotes: 5
Views: 7548
Reputation: 2647
The Autodiscover property will work out the Service URL using just the emal address passed in. If the AutoDiscover redirects then the autodiscover will fail.
You can use it to find the endpoint if you don't know it.
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);
service.Url //Null
service.AutodiscoverUrl("[email protected]", (discoverURL) => true);
service.Url //https://exchange.example.com/ews/exchange.asmx
Note:I use the lamba (discoverURL) => true
to always accept the url, if your getting untrusted emails then you may want to validate the url returned before running the discovery.
Upvotes: 3
Reputation: 172578
The MSDN gives the answer straight away:
Initializes the Url property to the Exchange Web Services (EWS) endpoint for a specified email address by calling the Autodiscover service.
Remarks:
If an Autodiscover server returns a redirect HTTP status code, this method will generate an AutodiscoverLocalException with the Message property set to a string such as "Autodiscover blocked a potentially insecure redirection to https://autodiscover.contoso.com/autodiscover/autodiscover.xml. To allow Autodiscover to follow the redirection, use the AutodiscoverUrl(string, AutodiscoverRedirectionUrlValidationCallback) overload." This exception is generated for all redirect responses, regardless of the validity of the URL returned in the redirect response.
Upvotes: 0