Nextcloud Mail app with Dovecot

Versions:
Debian 11
Nextcloud Hub 3 25.0.2
Mail 2.2.1
Dovecot 2.3
Postfix 3.5

I’m trying to replace roundcube on my mail server with the Mail app on Nextcloud. Nextcloud is on one VM, and I have another VM dedicated to postfix/dovecot.

I currently have roundcube on the mail VM and it works just fine with IMAP-143 and Submission(587). I also have Nextcloud setup with Submission working just fine (also over port 587).

I have checked, both port 993 and 143 is open on the mail VM from Nextcloud. And the credentials I am using in Nextcloud mail app are the same as the ones in roundcube. The hostname (Internal DNS) is resolving just fine as well.

Trying with the following manual settings:
IMAP Host: admin@domain.com
Security: SSL/TLS
IMAP Port: 993

I get the following error with IMAP ssl/tls:

 IMAP server is not reachable 

Not very accurate because the port is open and Submission works just fine (both are using the same TLS cert on the mail VM).

If I try with IMAP STARTTLS:

 IMAP connection failed 

The nextcloud logs are completely useless, the last entry in /var/www/nextcloud/data/nextcloud.log only shows the install of the mail app, nothing else.
I send all the mail VM logs remotely, but don’t see anything about dovecot or postfix when attempting the connection from nextcloud. And nothing in /var/log/ for dovecot/postfix.

Dovecot configurations:

## Dovecot configuration file
!include_try /usr/share/dovecot/protocols.d/*.protocol
protocols = imap pop3 lmtp
listen = *
postmaster_address = postmaster at domain.com
dict {
}
!include conf.d/*.conf
disable_plaintext_auth = yes
auth_mechanisms = plain login
!include auth-system.conf.ext
service director {
  unix_listener login/director {
  }
  fifo_listener login/proxy-notify {
  }
  unix_listener director-userdb {
  }
  inet_listener {
  }
}
service imap-login {
}
service pop3-login {
}
service submission-login {
}

# Enable director for LMTP proxying:
protocol lmtp {
}
plugin {
}
mail_location = maildir:/var/mail/vhosts/%d/%n/
namespace inbox {
  inbox = yes
}
mail_privileged_group = mail
protocol !indexer-worker {
}
service imap-login {
  inet_listener imap {
    port = 143
  }
  inet_listener imaps {
    port = 993
    ssl = yes
  }
}
service pop3-login {
  inet_listener pop3 {
    port = 0
  }
  inet_listener pop3s {
    port = 995
    ssl = yes
  }
}
service submission-login {
  inet_listener submission {
  }
}
service lmtp {
  unix_listener /var/spool/postfix/private/dovecot-lmtp {
    mode = 0600
    user = postfix
    group = postfix
  }
}
service imap {
}
service pop3 {
}
service submission {
}
service auth {
  unix_listener /var/spool/postfix/private/auth {
    mode = 0660
    user = postfix
    group = postfix
  }
  unix_listener auth-userdb {
    mode = 0600
    user = vmail
  }
  user = dovecot
}
service auth-worker {
  user = vmail
}
service dict {
  unix_listener dict {
  }
}
ssl = required
ssl_cert = </etc/ssl/certs/mailtls-selfsigned.crt 
ssl_key = </etc/ssl/private/mailtls-selfsigned.key
ssl_client_ca_dir = /etc/ssl/certs
ssl_dh = </usr/share/dovecot/dh.pem
ssl_min_protocol = TLSv1.2
protocol lda {
}
namespace inbox {
  mailbox Drafts {
    special_use = \Drafts
  }
  mailbox Junk {
    special_use = \Junk
  }
  mailbox Trash {
    special_use = \Trash
  }
  mailbox Sent {
    special_use = \Sent
  }
  mailbox "Sent Messages" {
    special_use = \Sent
  }
}
protocol imap {
  mail_max_userip_connections = 50
}
protocol lmtp {
}
protocol pop3 {
}
passdb {
  driver = dict
  args = /etc/dovecot/dovecot-dict-auth.conf.ext
}
userdb {
  driver = dict
  args = /etc/dovecot/dovecot-dict-auth.conf.ext
}
passdb {
  driver = sql
  args = /etc/dovecot/dovecot-sql.conf.ext
}
userdb {
  driver = static
  args = uid=vmail gid=vmail home=/var/mail/vhosts/%d/%n
}

I did a tcpdump on the mail VM, and saw 65 packets before the Nextcloud Mail app gave me the above errors.
I would assume the issue is Nextcloud is bailing on the connection due to a configuration issue on its side.
I do use a self-signed cert for the mail VM, but the sendmail built into Nextcloud settings works just fine.

Can anyone help me with this?

Please have a look at mail/admin.md at main · nextcloud/mail · GitHub for more troubleshooting pointers.

Do the mail app php configuration options go in the main nextcloud php config? at /var/www/nextcloud/config/config.php?

That’s not a hostname.

Whoops, thats a typo.

Anyways, the self signed cert was the issue. The dont verify cert option in php worked.