Skip to content

How to Fix Dovecot IMAP Connection Error

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about How to Fix Dovecot IMAP Connection Error. We cover key concepts, practical examples, and best practices.

Dovecot IMAP returns Connection refused or Login failed when clients try to connect — the IMAP service is not listening, authentication is failing, or the SSL certificate is invalid.

The Problem

$ openssl s_client -connect mail.example.com:993
connect: Connection refused

Step-by-Step Fix

Step 1: Check Dovecot status

sudo systemctl status dovecot

Step 2: Verify ports are listening

sudo netstat -tulpn | grep -E "993|143"

Step 3: Configure IMAP protocols

# /etc/dovecot/dovecot.conf
protocols = imap pop3 imaps pop3s
listen = *, ::

Step 4: Configure SSL

# /etc/dovecot/conf.d/10-ssl.conf
ssl = required
ssl_cert = </etc/ssl/certs/mail.example.com.crt
ssl_key = </etc/ssl/private/mail.example.com.key
ssl_min_protocol = TLSv1.2

Step 5: Configure authentication

# /etc/dovecot/conf.d/10-auth.conf
disable_plaintext_auth = yes
auth_mechanisms = plain login
!include auth-system.conf.ext

Step 6: Restart Dovecot

sudo systemctl restart dovecot

Step 7: Test IMAP connection

openssl s_client -connect mail.example.com:993

Expected:

* OK [CAPABILITY IMAP4rev1...] Dovecot ready.

Prevention Tips

  • Use ssl = required to enforce encrypted connections
  • Monitor Dovecot logs at /var/log/dovecot/*.log
  • Test IMAP connection with telnet or openssl
  • Restrict IMAP access by IP with firewall rules

Common Mistakes with imap connect

  1. Misunderstanding that String is [Char] with poor performance for large text operations
  2. Using foldl instead of foldl' causing stack overflow on large lists
  3. Forgetting deriving (Show, Eq) on custom data types needed for debugging

These mistakes appear frequently in real-world DOVECOT code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### Why does Dovecot refuse IMAP connections?

Dovecot might not be running, bound to the wrong interface, or the port is blocked by a firewall. Check sudo systemctl status dovecot and sudo netstat -tulpn | grep dovecot. Also verify that protocols includes imap in the config.

How do I test IMAP login from the command line?

Use openssl s_client -connect mail.example.com:993 then send:

a1 LOGIN username password
a2 LIST "" "*"
a3 LOGOUT

If authentication works, Dovecot is properly configured for IMAP.

What is the difference between IMAP on port 143 and 993?

Port 143 uses STARTTLS (upgrades from plain to encrypted). Port 993 uses implicit TLS (always encrypted from the start). Most modern clients prefer port 993 with implicit TLS. Both require valid SSL certificates.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro