GetAutodiscoverUrlWithExchangeVersionAndCallback method

Future<Uri> GetAutodiscoverUrlWithExchangeVersionAndCallback(
  1. String emailAddress,
  2. ExchangeVersion requestedServerVersion,
  3. AutodiscoverRedirectionUrlValidationCallback validateRedirectionUrlCallback
)
Gets the EWS URL from Autodiscover. The email address. Exchange version. The validate redirection URL callback.

Implementation

Future<Uri> GetAutodiscoverUrlWithExchangeVersionAndCallback(
  String emailAddress,
  ExchangeVersion requestedServerVersion,
  AutodiscoverRedirectionUrlValidationCallback validateRedirectionUrlCallback,
) async {
  AutodiscoverService autodiscoverService =
      AutodiscoverService.withExchangeServiceAndExchangeVersion(
          this,
          requestedServerVersion,
        )
        ..RedirectionUrlValidationCallback = validateRedirectionUrlCallback
        ..EnableScpLookup = EnableScpLookup;

  GetUserSettingsResponse response =
      await autodiscoverService.GetUserSettingsWithSmtpAddress(emailAddress, [
        UserSettingName.InternalEwsUrl,
        UserSettingName.ExternalEwsUrl,
      ]);

  switch (response.ErrorCode) {
    case AutodiscoverErrorCode.NoError:
      return GetEwsUrlFromResponse(response, autodiscoverService.IsExternal);

    case AutodiscoverErrorCode.InvalidUser:
      throw ServiceRemoteException("InvalidUser($emailAddress)");

    case AutodiscoverErrorCode.InvalidRequest:
      throw ServiceRemoteException(
        "InvalidAutodiscoverRequest(${response.ErrorMessage}",
      );

    default:
      TraceMessage(
        enumerations.TraceFlags.AutodiscoverConfiguration,
        "No EWS Url returned for user $emailAddress, error code is ${response.ErrorCode}",
      );

      throw ServiceRemoteException(response.ErrorMessage!);
  }
}