Hi,
I am using Aspose to fetch mails iteratively after a pool interval of >= 30 seconds for an email account using Microsoft Oauth authentication. And below is the code to define the mail settings
protected override async Task OnGetClientAsync()
{
        try
        {
            var client = new ImapClient(Settings.Host, Settings.Port)
            {
                SecurityOptions = Settings.UseSsl ? SecurityOptions.SSLAuto : SecurityOptions.Auto,
                UseAuthentication = true,
                UseDefaultCredentials = false
            };
            //Set timeout.
            if (Settings.Timeout != null)
            {
                client.Timeout = Settings.Timeout.Value;
            }
            switch (Settings.Authentication)
            {
                case BasicAuthentication auth:
                    client.Username = auth.GetFullUsername();
                    client.Password = auth.Password;
                    client.UseAuthentication = !auth.UseOpenRelay;
                    break;
                case GoogleOAuthAuthentication auth:
                    client.Username = auth.Username;
                    client.AccessToken = await GoogleOAuthAuthentication.CreateAccessTokenAsync(auth).ConfigureAwait(false);
                    break;
                case MicrosoftOAuthAuthentication auth:
                    ITokenProvider tokenProvider = new AzureTokenProvider(auth.TenantId, auth.AppId, auth.Username, auth.Secret, auth.Scopes.ToArray());
                    client.Username = auth.Username;
                    client.TokenProvider = tokenProvider;
                    break;
                default:
                    throw new NotSupportedException($"Authentication of type {Settings.Authentication?.GetType().Name ?? "undefined"} is not supported for {nameof(ImapMailClient)}.");
            }
            // Select the correct folder from the settings.
            client.SelectFolder(Settings.FolderName);
            // Return the client.
            WriteLog(BaseLogType.Success, $"{nameof(ImapMailClient)} successfully created.");
            return client;
        }
        catch (Exception ex)
        {
            WriteLog(BaseLogType.Error, $"An error occured while creating {nameof(ImapMailClient)}: {ex}");
            throw;
        }
    }
Here the code line " client.SelectFolder(Settings.FolderName); " throws the exception below
/**********************************************************************/
An error occured while creating ImapMailClient: TimeoutException: The operation ‘Connect’ terminated. Timeout ‘100000’ has been reached.
at #=zKsMZoQj7V8171J04kxP4KAui0J22.#=zxd769ac=(IAsyncResult #=zFBSKbgk=)
at #=zKsMZoQj7V8171J04kxP4KAui0J22.#=zoIFp4rM=()
at #=zCnpIhNu9ggZ6Em3x4Onn$N0iPaWQ.#=zPhsfbaLMbyEb(Int32 #=zDtVxeBo=, #=zfCU2qSy0a2_ihcIx82G4kNbg87UQ3qUIXQ== #=zzrMQxkc=)
at #=zKsMZoQj7V8171J04kxP4KAui0J22.#=zc20PShB5S7PN()
at #=zw$jR9sEqiBJWrRnUtmyNZMOwUM11wCi7dPd9oat6w$51.#=zc20PShB5S7PN()
at #=z4QXz97stZN24l4rqXV3xqGGnA9czZjxGMOdxPeiBI$1K…ctor(EmailClient #=zVtlkI7c=, String #=z9AND5dU=, Nullable1 #=zdYSWcIIDDBvN)    at Aspose.Email.Clients.Imap.ImapClient.BeginSelectFolder(IConnection connection, String folderName, Nullable1 readOnly, AsyncCallback callback, Object state)
at Aspose.Email.Clients.Imap.ImapClient.SelectFolder(IConnection connection, String folderName, Nullable1 readOnly)    at Aspose.Email.Clients.Imap.ImapClient.SelectFolder(String folderName)    at Onguard.Email.Clients.ImapMailClient.<OnGetClientAsync>d__7.MoveNext() 2021-03-18 5:29:25 PM Error : An error occured while connecting ImapClient: TimeoutException: The operation 'Connect' terminated. Timeout '100000' has been reached.    at #=zKsMZoQj7V8171J04kxP4KAui0J22.#=zxd769ac=(IAsyncResult #=zFBSKbgk=)    at #=zKsMZoQj7V8171J04kxP4KAui0J22.#=zoIFp4rM=()    at #=zCnpIhNu9ggZ6Em3x4Onn$N0iPaWQ.#=zPhsfbaLMbyEb(Int32 #=zDtVxeBo=, #=zfCU2qSy0a2_ihcIx82G4kNbg87UQ3qUIXQ== #=zzrMQxkc=)    at #=zKsMZoQj7V8171J04kxP4KAui0J22.#=zc20PShB5S7PN()    at #=zw$jR9sEqiBJWrRnUtmyNZMOwUM11wCi7dPd9oat6w$51.#=zc20PShB5S7PN()    at #=z4QXz97stZN24l4rqXV3xqGGnA9czZjxGMOdxPeiBI$1K..ctor(EmailClient #=zVtlkI7c=, String #=z9AND5dU=, Nullable1 #=zdYSWcIIDDBvN)
at Aspose.Email.Clients.Imap.ImapClient.BeginSelectFolder(IConnection connection, String folderName, Nullable1 readOnly, AsyncCallback callback, Object state)    at Aspose.Email.Clients.Imap.ImapClient.SelectFolder(IConnection connection, String folderName, Nullable1 readOnly)
at Aspose.Email.Clients.Imap.ImapClient.SelectFolder(String folderName)
at Onguard.Email.Clients.ImapMailClient.d__7.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Onguard.Email.Clients.MailClient2.<OnGetClientAsyncInternal>d__7.MoveNext() --- End of stack trace from previous location where exception was thrown ---    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)    at Onguard.Email.Clients.MailClient2.get_Client()
at Onguard.Email.Clients.ImapMailClient.ConnectAsync()
/**********************************************************************/
And sometimes the code below for creating the connection
    public override Task<bool> ConnectAsync()
    {
        try
        {
            if (Client?.ConnectionState == ConnectionState.Open)
            {
                return Task.FromResult(true);
            }
            return Task.FromResult(Client.CreateConnection() != null);
        }
        catch (Exception ex)
        {
            WriteLog(BaseLogType.Error, $"An error occured while connecting {nameof(ImapClient)}: {ex}");
            return Task.FromResult(false);
        }
    }
too throws an error below
Error : An error occured while creating ImapMailClient: AsposeException: AE_18_1_0002 NO [ALERT] Too many simultaneous connections. (Failure) ---> AsposeException: AE_18_1_0002 NO [ALERT] Too many simultaneous connections. (Failure)
even though using the preexisting open connection has been checked for.
Aspose.Email assembly version used (20.11.0.0)
Please help resolving the issues.
Thanks & Regards,
Yogesh