I had problems with enabling the ACME method for the main domain (mail.example.com), because I had to re-install Stalwart from scratch for I could not upgrade from 0.15.x to 0.16. So when I first installed Stalwart 0.16, Let’s Encrypt did not issue a certificate for this domain due to rate limits.
So I used a manual ZeroSSL certificate for mail.example.com. Then when the limits reset for Let’s Encrypt, I changed the domain’s DNS management to automatic and had a DNS-01 challenged wildcard certificate (*.example.com, mail.example.com)
Now the two certificates are installed and ZeroSSL is serving mail.example.com but it’s coming to the end of its validity. Stalwart admin panel wouldn’t let me delete this ZeroSSL certificate as it’s in use.
So the question is, how can I change the certificate Stalwart is served, to the new wildcard certificate that’s present on the panel?
I understand that topics in this category are triaged by a bot first but a human reply will follow up. If I’d prefer a human-only reply, I’ll add the no-ai tag to my topic.
This is the answer. Let me read the certificates.md doc fully for clarity.
Since Stalwart doesn’t assign certificates per-domain in config, selection happens automatically via SNI matching against the SAN list of every certificate stored in the system; when more than one certificate matches a hostname, the server logs tls.multiple-certificates-available and just picks the first match, which isn’t something you can force from the UI. The actual “in use” certificate that blocks deletion is almost certainly the one referenced by defaultCertificateId on the SystemSettings singleton (Settings › Network › General), which is the certificate served as the fallback whenever a client doesn’t send SNI, and is also what the WebUI considers “in use.”
To switch over:
Open Settings › Network › General in the WebUI and find the defaultCertificateId field.
Change it from the old ZeroSSL certificate to the new wildcard Certificate record.
Save, then try deleting the ZeroSSL certificate again, it should no longer be referenced and the delete should succeed.
If it’s still blocked after that, check whether any Http or NetworkListener/reverse-proxy related object elsewhere references that certificate explicitly, since any live reference will keep it from being deletable.