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 =
      new AutodiscoverService.withExchangeServiceAndExchangeVersion(
          this, requestedServerVersion)
        ..RedirectionUrlValidationCallback = validateRedirectionUrlCallback
        ..EnableScpLookup = this.EnableScpLookup;

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

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

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

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

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

      throw new ServiceRemoteException(response.ErrorMessage!);
  }
}