Insights

Outlook Shows a Certificate Warning for mail.yourdomain? Check the Name It Gets

November 7, 2026
0:00
Outlook or Thunderbird shows a warning that the certificate for mail.yourdomain.com is untrusted, or that the name on it does not match, yet the website loads with a valid padlock. It looks like the same SSL certificate should cover both, so people assume the mail client is broken. Usually it is not. The mail server chooses its certificate independently of the web server, and that choice depends on the name the client sends at the start of the encrypted connection. This article walks through that choice, from the TLS handshake to the code paths inside Dovecot and Exim. It also shows how to see exactly which certificate a mail port presents before anyone changes client settings.
When a browser opens https://yourdomain.com, it talks to Apache, Nginx, or LiteSpeed on port 443. That web server has its own list of virtual hosts and certificates. When Outlook checks mail, it talks to entirely different processes:
  • Dovecot handles IMAP on ports 993 and 143, and POP3 on 995 and 110.
  • Exim or Postfix handles SMTP on ports 465 and 587, and on 25 for server-to-server mail.
Each of these daemons loads its own certificate configuration. A valid web certificate proves only that the web server is configured correctly. It says nothing about which certificate is on disk for Dovecot or Exim, or whether the name mail.yourdomain.com is even covered by one. There is a second detail people miss. A certificate for yourdomain.com and www.yourdomain.com does not cover mail.yourdomain.com. The client compares the exact hostname it connected to against the Subject Alternative Name (SAN) list in the certificate. If mail.yourdomain.com is not on that list, and no wildcard like *.yourdomain.com covers it, the result is a name mismatch.
The certificate choice happens inside the TLS handshake, so it helps to know when that handshake starts. Mail uses two connection styles. With implicit TLS, used on ports 993, 995, and 465, encryption starts immediately:
  1. The client opens a TCP connection.
  2. Before any mail protocol text is exchanged, the client sends a TLS ClientHello message.
  3. The server reads the ClientHello, picks a certificate, and replies with ServerHello and its certificate chain.
  4. The client validates the chain against its trusted root store, then checks that the hostname it dialed appears in the certificate's SAN list.
With STARTTLS, used on ports 143 and 587, the connection starts in plain text:
  1. The server sends a greeting banner.
  2. The client sends EHLO for SMTP or CAPABILITY for IMAP, and the server advertises STARTTLS.
  3. The client sends STARTTLS, and the server agrees.
  4. From this point, the handshake is the same as above, starting with the ClientHello.
In both styles, the important piece is a field inside the ClientHello called Server Name Indication (SNI). SNI is the client saying, in effect, which hostname it is trying to reach. It travels unencrypted in the ClientHello because the server needs it before it can decide which certificate to send. If the client sends SNI with mail.yourdomain.com, the server has a chance to find a matching certificate. If the client sends no SNI, or the server has no certificate for that name, the server falls back to its default. Note what the server does not use. The domain in the login username, and the domain in the SMTP MAIL FROM command, both arrive after the handshake. By then the certificate has already been sent. The only name available at selection time is SNI, plus the local IP address the connection arrived on.
Both daemons rely on OpenSSL (or GnuTLS, for some Exim builds), and both follow the same basic pattern: a global default certificate, plus optional per-name overrides selected by SNI. In Dovecot, the TLS session is handled by the login processes, such as imap-login and pop3-login, before the user has authenticated. The global ssl_cert and ssl_key settings define the default. A local_name block overrides them for a specific SNI value. When the ClientHello arrives, the TLS library invokes a server name callback. Dovecot looks for a local_name block matching the requested name, swaps in that certificate, and continues the handshake. If nothing matches, the global certificate is used. In Exim, the main options tls_certificate and tls_privatekey define the certificate. They are expansion strings, which is Exim's term for configuration values evaluated at runtime. When the expansion references $tls_in_sni, Exim evaluates the option again after the ClientHello delivers the SNI value. That makes a per-domain lookup possible. If the variable is empty or the lookup finds no file, the expansion's fallback branch applies, and that fallback is typically the hostname certificate. Here is a simplified illustration of both mechanisms. Paths and names are placeholders, and the syntax is version dependent:
TEXT
# Dovecot 2.3-style syntax (Dovecot 2.4 renamed these settings)
ssl_cert = </etc/ssl/certs/server-hostname.pem
ssl_key = </etc/ssl/private/server-hostname.key

local_name mail.yourdomain.com {
  ssl_cert = </etc/ssl/certs/mail.yourdomain.com.pem
  ssl_key = </etc/ssl/private/mail.yourdomain.com.key
}

# Exim main section: pick a file by SNI, fall back to the hostname cert
tls_certificate = {if exists{/etc/exim/certs/{tls_in_sni}.crt}{/etc/exim/certs/${tls_in_sni}.crt}{/etc/exim/certs/hostname.crt}}
On control panels such as cPanel, you usually do not edit these settings by hand. The panel generates the per-domain mapping from the certificates it manages and sets the service certificate as the default. The mechanism underneath is the same, so the reasoning still applies. Check the panel's own service certificate settings and documentation rather than editing generated files, which are typically overwritten.
The fallback certificate on a shared or managed server is almost always issued for the server's own hostname, for example server1.example-host.net. It is valid and trusted. It simply carries the wrong name for a client that dialed mail.yourdomain.com. That is why the warning typically reads as a mismatch rather than an expired or self-signed certificate. When it does read as untrusted, the fallback may be a self-signed default, or the server may not be sending its intermediate certificate. The fallback is triggered when there is no match for the SNI value. The common causes are:
  • No certificate covering mail.yourdomain.com exists on the server. Automated issuance often validates each name over HTTP or DNS. If the mail subdomain's DNS record points somewhere else, validation for that name can fail while the main domain succeeds.
  • The mail subdomain resolves to a different server than the one hosting the mailbox. This is common after a migration where the A record for the mail subdomain was missed.
  • The certificate exists, but the daemon was not reloaded after it was installed or renewed. In that case it may still be serving older material. Whether a reload is required depends on the version and configuration.
  • The client sends no SNI, or connects using a different name than the one shown in its settings. Outlook's Autodiscover, for example, can supply the server hostname instead.
It is easy to tell users to accept the warning permanently. That hides the problem and trains users to accept certificate prompts, which is exactly the habit you do not want them to have.
Before changing anything in Outlook, look at what the port actually presents. openssl s_client performs the same handshake as the mail client and prints the certificate it receives. The commands below are read-only:
BASH
# IMAP over implicit TLS (993), sending SNI for the mail subdomain
openssl s_client -connect mail.yourdomain.com:993 -servername mail.yourdomain.com </dev/null 2>/dev/null | openssl x509 -noout -subject -issuer -ext subjectAltName

# SMTP submission with STARTTLS (587)
openssl s_client -connect mail.yourdomain.com:587 -starttls smtp -servername mail.yourdomain.com </dev/null 2>/dev/null | openssl x509 -noout -subject -issuer -ext subjectAltName

# Same IMAP port with no SNI, to see the fallback certificate
openssl s_client -connect mail.yourdomain.com:993 -noservername </dev/null 2>/dev/null | openssl x509 -noout -subject -ext subjectAltName
Illustrative output format, showing the hostname fallback:
TEXT
subject=CN = server1.example-host.net
issuer=C = XX, O = Example CA, CN = Example Issuing CA
X509v3 Subject Alternative Name:
    DNS:server1.example-host.net
Read the results in this order:
  1. If the SNI test returns a certificate with mail.yourdomain.com in the SAN list, the server is fine. The client is either not sending SNI or is connecting with a different name, so check the exact server name in its account settings.
  2. If the SNI test returns the hostname certificate, the server has no match for that name. The fix belongs on the server.
  3. If the names match but the client still says untrusted, drop the pipe to openssl x509 and read the Verify return code line in the full s_client output. A missing intermediate certificate typically shows up there.
Also run dig against the mail subdomain and confirm that it resolves to the server you just tested. A perfect certificate on the wrong machine does not help. The -ext option needs OpenSSL 1.1.1 or newer. On older builds, replace it with -text and look for the Subject Alternative Name section.
Once s_client shows the hostname certificate under SNI, the work is on the server side. The usual sequence is:
  1. Make sure the mail subdomain's DNS points to the server that holds the mailbox.
  2. Get mail.yourdomain.com included in a certificate. Depending on the setup, that means either reissuing the domain's certificate with the extra name or issuing a separate certificate for it.
  3. Make sure Dovecot and Exim map that name to the certificate, either through the panel or through config like the example above.
  4. Reload the services if your version requires it.
  5. Run the same s_client commands again. Only when they return the right name should anyone look at client settings.
There is a valid workaround: point the client at the server hostname, since the fallback certificate matches it. It works immediately. The trade-off is that every mail client is now tied to an infrastructure name that changes when the account moves to another server, so it suits a short-term unblock better than a permanent setup. The practical habit is simple. When a mail client complains about a certificate, ask which name it dialed, then use openssl s_client with that exact name on the exact port. The answer tells you whether to fix DNS, the certificate, the daemon mapping, or the client. You can usually find it in a minute, without guessing.

Join My Newsletter & Get Updates!

Get notified whenever a new technical guide, server infrastructure breakdown, or personal reflection goes live, plus a curated weekly digest.