Autodiscover

Exchange Web Services can be accessed using a direct URL or using Autodiscover. If your on-premises Exchange infrastructure is fairly large, you will need to ensure you are connecting to the correct server. Typically you would provide a specific address that you would want to communicate with, but with Exchange they offer an Autodiscover service.

Autodiscover is exactly what it sounds like, it will auto discover which server you should be communicating with all through a central endpoint/url.

This documentation provides details about the Autodiscover class within the pyews package. If you would like to find out more information about Exchange’s Autodiscover service, please refer to Microsoft’s documentation.

This class is used in the UserConfiguration class when you decide to use Exchange Web Services Autodiscover service endpoints.

A class used to connect to Exchange Web Services using the Autodiscover service endpoint

The Autodiscover class can be used with both Office 365 and on-premises Exchange 2010 to 2019. Currently, it has been thoroughly tested with Office 365 but not so much with the on-premises versions of Exchange.

Example:

There two typical methods of using the Autodiscover class. These behave slightly differently depending on your needs.

  1. If you know the Autodiscover URL for your on-premises or Office 365 Exchange Autodiscover service then you can provide this directly
Autodiscover(
    credentialObj, 
    endpoint='https://outlook.office365.com/autodiscover/autodiscover.svc',
    exchangeVersion='Office365'
)
  1. If you do not know the Autodiscover URL then you can set create_endpoint_list to True to have the Autodiscover class attempt to generate URL endpoints for you
Autodiscover(
    credentialObj,
    create_endpoint_list=True
)
Args:
credentials (Credentials): An object created using the Credentials class endpoint (str, optional): Defaults to None. If you want to specify a different Autodiscover endpoint then provide the url here exchangeVersion (str, optional): Defaults to None. An exchange version string create_endpoint_list (bool, optional): Defaults to False. If you want the Autodiscover class to generate a list of endpoints to try based on a users email address