Getting "IMAP server is not reachable" error on set up

Hello! I am trying to connect to my email server and use nextcloud Mail app for emails. Some details about the installation:

  1. Dockerized installation
  2. Running behind nginx proxy
  3. Mail server is on a different server and network and I am using the settings from the mail provider that work with other mail clients
  4. The smtp settings for notifications from nextcloud work through the same server with a different account

Steps that lead to error :

  1. Install Mail app
  2. Go to set up account
  3. Manual set up all configuration since automatically doesn’t work
  4. Use settings from mail provider (SSL/TLS)
  5. Get error “Manual config failed. IMAP server is not reachable.”

Error log shows :

{“reqId”:“RZt1vs3EBKVr2zXKF2Zm”,“level”:3,“time”:“2022-10-02T06:26:24+00:00”,“remoteAddr”:“{MY-IP}”,“user”:“{MY-USERNAME}”,“app”:“core”,“method”:“PROPFIND”,“url”:“/remote.php/dav/files/{MY-USERNAME}/”,“message”:“User backend OC_User_IMAP not found.”,“userAgent”:“Mozilla/5.0 (Windows) mirall/3.4.0stable-Win64 (build 20211129) (Nextcloud, windows-10.0.19042 ClientArchitecture: x86_64 OsArchitecture: x86_64)”,“version”:“24.0.5.1”,“data”:{“app”:“core”}}

This I have tried already :

  1. Defining user_backends in config.php
  2. Added ‘app.mail.verify-tls-peer’ => false in config.php
  3. Manually adding the IP from my mail server in /etc/hosts (which is totally not required since smtp works)
  4. Installing php imap using :
apt-get update
apt-get install -y --no-install-recommends libc-client-dev libkrb5-dev
docker-php-ext-configure imap --with-kerberos --with-imap-ssl
docker-php-ext-install imap

And in the end I restarted the whole container, just to be sure.

Still the same thing happens.