Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Email delivery

Dovecot refuses to start: Can't load SSL certificate, no valid PEM certificate

ErrorCan't load SSL certificate (ssl_cert setting): There is no valid PEM certificate

Short answer

Dovecot reads the ssl_cert setting as the file's contents, not a path, so in 2.3 the value must start with a less-than sign. After that, the file must start with your server certificate and then the intermediates. Dovecot 2.4 uses new setting names that take a plain path. Match the config to your version.

  • Applies to Dovecot 2.3, Dovecot 2.4, OpenSSL 3, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Print the settings Dovecot really uses and check how the certificate value is written, then ask which version you run.

    doveconf -n | grep -E '^ssl'
    dovecot --version
  2. 2Match what you see, then jump to its fix

    1. 1ssl_cert = /etc/ssl/certs/mail.example.com.crt in doveconf -n, with no leading <The path in ssl_cert has no less-than sign (Dovecot 2.3)Fix
    2. 2The file opens, but it holds only an intermediate CA, or the intermediates come firstThe certificate file does not start with your server certificateFix
    3. 3dovecot --version says 2.4 while your files use ssl_cert and ssl_key, or the reverseA 2.3 configuration is used on Dovecot 2.4, or the other way roundFix

What does the error look like?

  • Can't load SSL certificate (ssl_cert setting): There is no valid PEM certificate
  • doveconf: Error: ssl enabled, but ssl_cert not set
  • IMAP and POP3 logins fail with a TLS error after you changed the certificate

Cause 1 of 3

The path in ssl_cert has no less-than sign (Dovecot 2.3)

1Check

In Dovecot 2.3 the value holds the contents of the file. The docs say the less-than sign is mandatory and that leaving it out causes an error. Look at the line in your config.

grep -R -nE '^\s*ssl_(cert|key)' /etc/dovecot/

2Fix

Add the sign directly before the path in both ssl_cert and ssl_key.

ssl_cert = </etc/ssl/certs/mail.example.com.crt
ssl_key = </etc/ssl/private/mail.example.com.key

3Verify

Reload Dovecot and watch the log for the error to be gone.

sudo systemctl reload dovecot
sudo journalctl -u dovecot -n 20 --no-pager

Confirmed by doc.dovecot.org

Did this fix it?

Cause 2 of 3

The certificate file does not start with your server certificate

1Check

The Dovecot docs say the ssl_cert file must contain the server certificate first, then each signing CA in order. Print the subject of the certificate OpenSSL reads from the file; it should be your mail host name.

openssl x509 -in /etc/ssl/certs/mail.example.com.crt -noout -subject

2Fix

Rebuild the file in the right order: your certificate, then the intermediates, or use the full-chain file your certificate provider gives you.

cat mail.example.com.crt intermediate.crt > /etc/ssl/certs/mail.example.com.fullchain.crt

3Verify

Point ssl_cert at the combined file, reload, and test the handshake.

openssl s_client -servername mail.example.com -connect mail.example.com:imaps

Confirmed by doc.dovecot.org

Did this fix it?

Cause 3 of 3

A 2.3 configuration is used on Dovecot 2.4, or the other way round

1Check

The 2.4 documentation writes the settings as ssl_server_cert_file and ssl_server_key_file with a plain path, with no less-than sign. Compare your file with the documentation for the version that is installed.

dovecot --version

2Fix

Write the certificate settings in the style of your installed version. For 2.4:

ssl_server_cert_file = /etc/dovecot/dovecot.crt
ssl_server_key_file = /etc/dovecot/dovecot.key

3Verify

Check that doveconf accepts the file with no errors, then reload.

doveconf -n > /dev/null
sudo systemctl reload dovecot

Confirmed by doc.dovecot.org

Did this fix it?

How do I stop it coming back?

  • Keep the key readable only by root; the Dovecot docs prefer root:root 0400 for the key file.
  • After every renewal, run doveconf -n and an openssl s_client test before you walk away.
  • Note the Dovecot version next to the config in your server notes, so the right documentation is used.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Related fixes

Email

Postfix refuses to send with "Relay access denied"

454 4.7.1 <user@example.net>: Relay access denied

Postfix says Relay access denied when a client asks it to deliver to a domain it does not host, and the client is neither listed in mynetworks nor logged in with SASL.

5 causes, each with a fix

Email

Mail from your own domain keeps landing in the spam folder

dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=example.com

Open a message that went to spam and read its Authentication-Results header: it shows whether SPF, DKIM and DMARC passed, and for which domain.

5 causes, each with a fix

Email

Outlook.com bounces your mail with 550 5.7.515

status=bounced (host hotmail-com.olc.protection.outlook.com[...] said: 550 5.7.515 Access denied

550 5.7.515 means Outlook.com counts your From domain as a high-volume sender (5,000 or more messages a day to Microsoft consumer addresses) and the message failed its authentication rules.

4 causes, each with a fix

Email

Django send_mail fails or hangs with an SSL error

smtplib.SMTPException raised from send_mail()

Django has two secure modes that must not be mixed: EMAIL_USE_TLS for explicit TLS (STARTTLS, usually port 587) and EMAIL_USE_SSL for implicit TLS (usually port 465).

4 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.