Installation d'un Serveur Mail Complet avec Postfix et Dovecot

Installation d'un Serveur Mail Complet avec Postfix et Dovecot

Guide complet pour configurer un serveur de messagerie professionnel sous Linux

Table des matières

  1. Introduction et Architecture
  2. Prérequis
  3. Installation des paquets
  4. Configuration DNS
  5. Configuration de Postfix
  6. Configuration de Dovecot
  7. Sécurisation avec SSL/TLS
  8. Authentification SASL
  9. Tests et Validation
  10. Dépannage

Introduction et Architecture

Qu'est-ce qu'un serveur mail ?

Un serveur mail gère l'envoi et la réception des emails. Notre configuration utilise deux composants principaux :

  • Postfix : Agent de transfert de mail (MTA) - gère l'envoi et la réception SMTP
  • Dovecot : Serveur IMAP/POP3 - permet aux clients de consulter leurs emails

Schéma d'Architecture Globale

┌─────────────────────────────────────────────────────────────────────────────┐
│                        ARCHITECTURE SERVEUR MAIL                            │
└─────────────────────────────────────────────────────────────────────────────┘

    INTERNET                        SERVEUR                         CLIENTS
    ────────                        ───────                         ───────

┌──────────────┐                ┌─────────────────────────────┐
│   Serveur    │    Port 25     │                             │
│   Externe    │ ──────────────▶│         POSTFIX             │
│   (SMTP)     │                │      (MTA - SMTP)           │
└──────────────┘                │                             │
                                │   ┌─────────────────────┐   │
                                │   │    File d'attente   │   │
                                │   │    (Mail Queue)     │   │
                                │   └─────────────────────┘   │
                                │              │              │
                                │              ▼              │
                                │   ┌─────────────────────┐   │
                                │   │     Maildir         │   │
                                │   │  /var/mail/vhosts/  │   │
                                │   └─────────────────────┘   │
                                │              │              │
                                └──────────────┼──────────────┘
                                               │
                                ┌──────────────┼──────────────┐
                                │              ▼              │
                                │         DOVECOT             │     ┌──────────┐
                                │     (IMAP/POP3 Server)      │────▶│ Outlook  │
                                │                             │     └──────────┘
                                │   Ports: 993 (IMAPS)        │     ┌──────────┐
                                │          995 (POP3S)        │────▶│Thunderbird│
                                │          587 (Submission)   │     └──────────┘
                                └─────────────────────────────┘     ┌──────────┐
                                                                    │ Webmail  │
                                                                    └──────────┘

Flux de Communication

┌─────────────────────────────────────────────────────────────────────────────┐
│                         FLUX EMAIL ENTRANT                                  │
└─────────────────────────────────────────────────────────────────────────────┘

  ┌─────────┐     ┌─────────┐     ┌─────────┐     ┌─────────┐     ┌─────────┐
  │ Envoyeur│     │   DNS   │     │ Postfix │     │ Dovecot │     │ Client  │
  │ Externe │     │  (MX)   │     │  (MTA)  │     │ (IMAP)  │     │  Mail   │
  └────┬────┘     └────┬────┘     └────┬────┘     └────┬────┘     └────┬────┘
       │               │               │               │               │
       │  Requête MX   │               │               │               │
       │──────────────▶│               │               │               │
       │               │               │               │               │
       │  Réponse MX   │               │               │               │
       │◀──────────────│               │               │               │
       │               │               │               │               │
       │          Connexion SMTP (port 25)             │               │
       │──────────────────────────────▶│               │               │
       │               │               │               │               │
       │               │               │  Stockage     │               │
       │               │               │  Maildir      │               │
       │               │               │──────────────▶│               │
       │               │               │               │               │
       │               │               │               │  Connexion    │
       │               │               │               │  IMAP (993)   │
       │               │               │               │◀──────────────│
       │               │               │               │               │
       │               │               │               │  Emails       │
       │               │               │               │──────────────▶│
       │               │               │               │               │
┌─────────────────────────────────────────────────────────────────────────────┐
│                         FLUX EMAIL SORTANT                                  │
└─────────────────────────────────────────────────────────────────────────────┘

  ┌─────────┐     ┌─────────┐     ┌─────────┐     ┌─────────┐     ┌─────────┐
  │ Client  │     │ Dovecot │     │ Postfix │     │   DNS   │     │Serveur  │
  │  Mail   │     │ (Auth)  │     │  (MTA)  │     │         │     │Distant  │
  └────┬────┘     └────┬────┘     └────┬────┘     └────┬────┘     └────┬────┘
       │               │               │               │               │
       │  SMTP Auth    │               │               │               │
       │  (port 587)   │               │               │               │
       │──────────────▶│               │               │               │
       │               │               │               │               │
       │               │  Validation   │               │               │
       │               │──────────────▶│               │               │
       │               │               │               │               │
       │               │               │  Requête MX   │               │
       │               │               │──────────────▶│               │
       │               │               │               │               │
       │               │               │  Réponse MX   │               │
       │               │               │◀──────────────│               │
       │               │               │               │               │
       │               │               │  Envoi SMTP   │               │
       │               │               │──────────────────────────────▶│
       │               │               │               │               │

Prérequis

Configuration Système Requise

Élément Minimum Recommandé
RAM 512 Mo 2 Go
Stockage 10 Go 50 Go+
OS Ubuntu 20.04+ / Debian 11+ Ubuntu 22.04 LTS
Réseau IP publique fixe IP dédiée

Ports à Ouvrir

┌─────────────────────────────────────────────────────────────────┐
│                    PORTS RÉSEAU REQUIS                          │
├────────┬──────────────┬─────────────────────────────────────────┤
│  Port  │   Protocole  │            Description                  │
├────────┼──────────────┼─────────────────────────────────────────┤
│   25   │   SMTP       │  Réception emails (serveur à serveur)   │
│  587   │   Submission │  Envoi emails (client authentifié)      │
│  465   │   SMTPS      │  SMTP over SSL (legacy)                 │
│  993   │   IMAPS      │  IMAP over SSL (consultation emails)    │
│  995   │   POP3S      │  POP3 over SSL (téléchargement emails)  │
└────────┴──────────────┴─────────────────────────────────────────┘

Vérifications Préalables

# Vérifier le hostname
hostname -f

# Vérifier que le port 25 n'est pas bloqué
telnet smtp.google.com 25

# Vérifier l'IP publique
curl ifconfig.me

Installation des Paquets

Ubuntu/Debian

# Mise à jour du système
sudo apt update && sudo apt upgrade -y

# Installation de Postfix
sudo apt install postfix postfix-policyd-spf-python -y

# Lors de l'installation, choisir :
# - Type de configuration : Site Internet
# - Nom de courrier : votre-domaine.com

# Installation de Dovecot
sudo apt install dovecot-core dovecot-imapd dovecot-pop3d dovecot-lmtpd -y

# Outils supplémentaires
sudo apt install certbot mailutils -y

CentOS/RHEL

# Installation des dépôts EPEL
sudo dnf install epel-release -y

# Installation de Postfix
sudo dnf install postfix -y

# Installation de Dovecot
sudo dnf install dovecot dovecot-pigeonhole -y

# Activer les services
sudo systemctl enable postfix dovecot

Configuration DNS

Enregistrements DNS Requis

┌─────────────────────────────────────────────────────────────────────────────┐
│                    CONFIGURATION DNS REQUISE                                │
└─────────────────────────────────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────────────────────────────────┐
│  TYPE  │        NOM         │           VALEUR              │    TTL       │
├────────┼────────────────────┼───────────────────────────────┼──────────────┤
│   A    │  mail              │  203.0.113.10                 │    3600      │
│   MX   │  @                 │  10 mail.votre-domaine.com    │    3600      │
│  TXT   │  @                 │  v=spf1 mx a -all             │    3600      │
│  TXT   │  _dmarc            │  v=DMARC1; p=quarantine       │    3600      │
│  PTR   │  10.113.0.203      │  mail.votre-domaine.com       │    3600      │
└────────┴────────────────────┴───────────────────────────────┴──────────────┘

Légende :
  • A    : Pointe le sous-domaine "mail" vers l'IP du serveur
  • MX   : Indique le serveur mail pour le domaine
  • TXT  : SPF pour l'authentification des emails sortants
  • TXT  : DMARC pour la politique de traitement des emails
  • PTR  : Reverse DNS (à configurer chez l'hébergeur)

Vérification DNS

# Vérifier l'enregistrement MX
dig MX votre-domaine.com +short

# Vérifier l'enregistrement A
dig A mail.votre-domaine.com +short

# Vérifier le SPF
dig TXT votre-domaine.com +short

# Vérifier le reverse DNS
dig -x VOTRE_IP_PUBLIQUE +short

Configuration de Postfix

Architecture Interne de Postfix

┌─────────────────────────────────────────────────────────────────────────────┐
│                    ARCHITECTURE INTERNE POSTFIX                             │
└─────────────────────────────────────────────────────────────────────────────┘

                              ┌──────────────────┐
                              │    smtpd         │◀─── Port 25 (entrant)
                              │  (réception)     │◀─── Port 587 (submission)
                              └────────┬─────────┘
                                       │
                                       ▼
                              ┌──────────────────┐
                              │    cleanup       │
                              │  (vérification)  │
                              └────────┬─────────┘
                                       │
                                       ▼
                              ┌──────────────────┐
                              │     qmgr         │
                              │ (gestionnaire    │
                              │   de queue)      │
                              └────────┬─────────┘
                                       │
              ┌────────────────────────┼────────────────────────┐
              │                        │                        │
              ▼                        ▼                        ▼
     ┌──────────────┐         ┌──────────────┐         ┌──────────────┐
     │    smtp      │         │    lmtp      │         │   local      │
     │  (sortant)   │         │  (Dovecot)   │         │ (système)    │
     └──────────────┘         └──────────────┘         └──────────────┘
              │                        │                        │
              ▼                        ▼                        ▼
     Serveurs externes         Dovecot LMTP              /var/mail/

Fichier /etc/postfix/main.cf

# Créer une sauvegarde
sudo cp /etc/postfix/main.cf /etc/postfix/main.cf.backup

# Éditer le fichier principal
sudo nano /etc/postfix/main.cf
# =============================================================================
# POSTFIX - CONFIGURATION PRINCIPALE
# =============================================================================

# -----------------------------------------------------------------------------
# IDENTITÉ DU SERVEUR
# -----------------------------------------------------------------------------
myhostname = mail.votre-domaine.com
mydomain = votre-domaine.com
myorigin = $mydomain

# -----------------------------------------------------------------------------
# RÉSEAUX ET INTERFACES
# -----------------------------------------------------------------------------
inet_interfaces = all
inet_protocols = ipv4
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128

# -----------------------------------------------------------------------------
# BOÎTES AUX LETTRES
# -----------------------------------------------------------------------------
home_mailbox = Maildir/
mailbox_size_limit = 0
recipient_delimiter = +

# -----------------------------------------------------------------------------
# TLS/SSL
# -----------------------------------------------------------------------------
smtpd_tls_cert_file = /etc/letsencrypt/live/mail.votre-domaine.com/fullchain.pem
smtpd_tls_key_file = /etc/letsencrypt/live/mail.votre-domaine.com/privkey.pem
smtpd_tls_security_level = may
smtpd_tls_auth_only = yes
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s

smtp_tls_security_level = may
smtp_tls_loglevel = 1

# Protocoles et ciphers sécurisés
smtpd_tls_mandatory_protocols = !SSLv2, !SSLv3, !TLSv1, !TLSv1.1
smtpd_tls_protocols = !SSLv2, !SSLv3, !TLSv1, !TLSv1.1
smtp_tls_mandatory_protocols = !SSLv2, !SSLv3, !TLSv1, !TLSv1.1
smtp_tls_protocols = !SSLv2, !SSLv3, !TLSv1, !TLSv1.1

# -----------------------------------------------------------------------------
# AUTHENTIFICATION SASL (via Dovecot)
# -----------------------------------------------------------------------------
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
broken_sasl_auth_clients = yes

# -----------------------------------------------------------------------------
# RESTRICTIONS
# -----------------------------------------------------------------------------
smtpd_helo_required = yes
smtpd_helo_restrictions =
    permit_mynetworks,
    permit_sasl_authenticated,
    reject_invalid_helo_hostname,
    reject_non_fqdn_helo_hostname

smtpd_sender_restrictions =
    permit_mynetworks,
    permit_sasl_authenticated,
    reject_non_fqdn_sender,
    reject_unknown_sender_domain

smtpd_recipient_restrictions =
    permit_mynetworks,
    permit_sasl_authenticated,
    reject_unauth_destination,
    reject_non_fqdn_recipient,
    reject_unknown_recipient_domain

# -----------------------------------------------------------------------------
# LIMITES ET PERFORMANCES
# -----------------------------------------------------------------------------
message_size_limit = 52428800
mailbox_size_limit = 0
smtpd_client_connection_count_limit = 10
smtpd_client_connection_rate_limit = 30

Fichier /etc/postfix/master.cf

sudo nano /etc/postfix/master.cf
# =============================================================================
# POSTFIX - SERVICES
# =============================================================================

# Service SMTP standard (port 25)
smtp      inet  n       -       y       -       -       smtpd

# Submission (port 587) - pour les clients authentifiés
submission inet n       -       y       -       -       smtpd
  -o syslog_name=postfix/submission
  -o smtpd_tls_security_level=encrypt
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_tls_auth_only=yes
  -o smtpd_reject_unlisted_recipient=no
  -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject
  -o milter_macro_daemon_name=ORIGINATING

# SMTPS (port 465) - SMTP over SSL
smtps     inet  n       -       y       -       -       smtpd
  -o syslog_name=postfix/smtps
  -o smtpd_tls_wrappermode=yes
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_reject_unlisted_recipient=no
  -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject
  -o milter_macro_daemon_name=ORIGINATING

Configuration de Dovecot

Architecture Interne de Dovecot

┌─────────────────────────────────────────────────────────────────────────────┐
│                    ARCHITECTURE INTERNE DOVECOT                             │
└─────────────────────────────────────────────────────────────────────────────┘

   Clients Mail                    Dovecot                      Stockage
   ───────────                    ─────────                     ────────

┌────────────┐
│  Outlook   │──┐
└────────────┘  │         ┌─────────────────────────────┐
                │         │                             │
┌────────────┐  │  IMAPS  │   ┌─────────────────────┐   │
│Thunderbird │──┼────────▶│   │    imap-login       │   │
└────────────┘  │  (993)  │   │    (authentif.)     │   │
                │         │   └──────────┬──────────┘   │
┌────────────┐  │         │              │              │
│   Mobile   │──┘         │              ▼              │
└────────────┘            │   ┌─────────────────────┐   │     ┌───────────────┐
                          │   │    imap             │   │     │               │
                          │   │    (protocole)      │   │────▶│   Maildir     │
                          │   └─────────────────────┘   │     │               │
                          │                             │     │ /var/mail/    │
                          │   ┌─────────────────────┐   │     │   vhosts/     │
                          │   │    auth             │───┼────▶│   domain/     │
                          │   │    (SASL)           │   │     │     user/     │
                          │   └──────────┬──────────┘   │     │               │
                          │              │              │     └───────────────┘
                          │              ▼              │
                          │   ┌─────────────────────┐   │
       Postfix ◀──────────│   │    auth-userdb      │   │
       (SASL)             │   │    (socket)         │   │
                          │   └─────────────────────┘   │
                          │                             │
                          └─────────────────────────────┘

Fichier /etc/dovecot/dovecot.conf

sudo nano /etc/dovecot/dovecot.conf
# =============================================================================
# DOVECOT - CONFIGURATION PRINCIPALE
# =============================================================================

# Protocoles activés
protocols = imap pop3 lmtp

# Écouter sur toutes les interfaces
listen = *, ::

# Inclure les configurations modulaires
!include conf.d/*.conf

Fichier /etc/dovecot/conf.d/10-mail.conf

sudo nano /etc/dovecot/conf.d/10-mail.conf
# =============================================================================
# DOVECOT - CONFIGURATION STOCKAGE MAIL
# =============================================================================

# Emplacement des boîtes mail (format Maildir)
mail_location = maildir:~/Maildir

# Namespace pour la boîte de réception
namespace inbox {
  inbox = yes
}

# Utilisateur/groupe pour accéder aux mails
mail_uid = vmail
mail_gid = vmail

# Privilèges
mail_privileged_group = mail

# Première UID/GID valide
first_valid_uid = 1000
first_valid_gid = 1000

Fichier /etc/dovecot/conf.d/10-auth.conf

sudo nano /etc/dovecot/conf.d/10-auth.conf
# =============================================================================
# DOVECOT - AUTHENTIFICATION
# =============================================================================

# Désactiver l'authentification en clair sans SSL
disable_plaintext_auth = yes

# Mécanismes d'authentification
auth_mechanisms = plain login

# Inclure la configuration système
!include auth-system.conf.ext

Fichier /etc/dovecot/conf.d/10-ssl.conf

sudo nano /etc/dovecot/conf.d/10-ssl.conf
# =============================================================================
# DOVECOT - CONFIGURATION SSL/TLS
# =============================================================================

# Activer SSL
ssl = required

# Certificats Let's Encrypt
ssl_cert = </etc/letsencrypt/live/mail.votre-domaine.com/fullchain.pem
ssl_key = </etc/letsencrypt/live/mail.votre-domaine.com/privkey.pem

# Protocoles autorisés (désactiver les anciens)
ssl_min_protocol = TLSv1.2

# Préférer les ciphers du serveur
ssl_prefer_server_ciphers = yes

# Ciphers sécurisés
ssl_cipher_list = ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384

Fichier /etc/dovecot/conf.d/10-master.conf

sudo nano /etc/dovecot/conf.d/10-master.conf
# =============================================================================
# DOVECOT - SERVICES ET SOCKETS
# =============================================================================

service imap-login {
  inet_listener imap {
    port = 0  # Désactivé (non sécurisé)
  }
  inet_listener imaps {
    port = 993
    ssl = yes
  }
}

service pop3-login {
  inet_listener pop3 {
    port = 0  # Désactivé (non sécurisé)
  }
  inet_listener pop3s {
    port = 995
    ssl = yes
  }
}

service lmtp {
  unix_listener /var/spool/postfix/private/dovecot-lmtp {
    mode = 0600
    user = postfix
    group = postfix
  }
}

# Socket d'authentification pour Postfix
service auth {
  unix_listener /var/spool/postfix/private/auth {
    mode = 0666
    user = postfix
    group = postfix
  }
  
  unix_listener auth-userdb {
    mode = 0600
    user = vmail
  }
  
  user = dovecot
}

service auth-worker {
  user = vmail
}

Sécurisation avec SSL/TLS

Obtenir un Certificat Let's Encrypt

# Arrêter temporairement les services
sudo systemctl stop postfix dovecot

# Obtenir le certificat
sudo certbot certonly --standalone -d mail.votre-domaine.com

# Redémarrer les services
sudo systemctl start postfix dovecot

Renouvellement Automatique

# Créer un script de renouvellement
sudo nano /etc/letsencrypt/renewal-hooks/post/mail-services.sh
#!/bin/bash
systemctl reload postfix
systemctl reload dovecot
# Rendre exécutable
sudo chmod +x /etc/letsencrypt/renewal-hooks/post/mail-services.sh

# Tester le renouvellement
sudo certbot renew --dry-run

Authentification SASL

Schéma d'Authentification

┌─────────────────────────────────────────────────────────────────────────────┐
│                    FLUX D'AUTHENTIFICATION SASL                             │
└─────────────────────────────────────────────────────────────────────────────┘

  ┌─────────┐     ┌─────────┐     ┌─────────┐     ┌─────────┐     ┌─────────┐
  │ Client  │     │ Postfix │     │ Socket  │     │ Dovecot │     │  PAM/   │
  │  Mail   │     │  SMTP   │     │  Auth   │     │  Auth   │     │ Passwd  │
  └────┬────┘     └────┬────┘     └────┬────┘     └────┬────┘     └────┬────┘
       │               │               │               │               │
       │  EHLO         │               │               │               │
       │──────────────▶│               │               │               │
       │               │               │               │               │
       │  250-AUTH     │               │               │               │
       │◀──────────────│               │               │               │
       │               │               │               │               │
       │  AUTH LOGIN   │               │               │               │
       │  user:pass    │               │               │               │
       │──────────────▶│               │               │               │
       │               │               │               │               │
       │               │  Verify      │               │               │
       │               │─────────────▶│               │               │
       │               │               │               │               │
       │               │               │  Check       │               │
       │               │               │─────────────▶│               │
       │               │               │               │               │
       │               │               │               │  Validate    │
       │               │               │               │─────────────▶│
       │               │               │               │               │
       │               │               │               │  OK/FAIL     │
       │               │               │               │◀─────────────│
       │               │               │               │               │
       │               │               │  Result      │               │
       │               │               │◀─────────────│               │
       │               │               │               │               │
       │               │  Result      │               │               │
       │               │◀─────────────│               │               │
       │               │               │               │               │
       │  235 Auth OK  │               │               │               │
       │◀──────────────│               │               │               │
       │               │               │               │               │

Création d'un Utilisateur Mail

# Créer le groupe vmail
sudo groupadd -g 5000 vmail

# Créer l'utilisateur vmail
sudo useradd -g vmail -u 5000 vmail -d /var/mail

# Créer le répertoire de stockage
sudo mkdir -p /var/mail/vhosts/votre-domaine.com

# Définir les permissions
sudo chown -R vmail:vmail /var/mail/vhosts

# Créer un utilisateur système pour le mail
sudo useradd -m -s /bin/bash utilisateur1
sudo passwd utilisateur1

# Créer la structure Maildir
sudo -u utilisateur1 mkdir -p /home/utilisateur1/Maildir/{cur,new,tmp}

Tests et Validation

Script de Test Complet

#!/bin/bash
# test-mail-server.sh

echo "=== Test du Serveur Mail ==="

# Test 1: Vérifier que Postfix écoute
echo -n "Port 25 (SMTP): "
nc -zv localhost 25 2>&1 | grep -q "succeeded" && echo "OK" || echo "ERREUR"

echo -n "Port 587 (Submission): "
nc -zv localhost 587 2>&1 | grep -q "succeeded" && echo "OK" || echo "ERREUR"

# Test 2: Vérifier que Dovecot écoute
echo -n "Port 993 (IMAPS): "
nc -zv localhost 993 2>&1 | grep -q "succeeded" && echo "OK" || echo "ERREUR"

echo -n "Port 995 (POP3S): "
nc -zv localhost 995 2>&1 | grep -q "succeeded" && echo "OK" || echo "ERREUR"

# Test 3: Vérifier le certificat SSL
echo -n "Certificat SSL: "
openssl s_client -connect localhost:993 -servername mail.votre-domaine.com </dev/null 2>/dev/null | grep -q "Verify return code: 0" && echo "OK" || echo "VÉRIFIER"

# Test 4: Vérifier la configuration Postfix
echo -n "Configuration Postfix: "
postfix check 2>&1 | grep -q "error" && echo "ERREUR" || echo "OK"

# Test 5: Vérifier la configuration Dovecot
echo -n "Configuration Dovecot: "
dovecot -n 2>&1 | grep -q "Error" && echo "ERREUR" || echo "OK"

echo "=== Fin des Tests ==="

Envoyer un Email de Test

# Via la ligne de commande
echo "Ceci est un test" | mail -s "Test Email" [email protected]

# Vérifier les logs
sudo tail -f /var/log/mail.log

Test avec Telnet/OpenSSL

# Test SMTP
openssl s_client -connect mail.votre-domaine.com:587 -starttls smtp

# Test IMAP
openssl s_client -connect mail.votre-domaine.com:993

Dépannage

Commandes de Diagnostic

# Vérifier l'état des services
sudo systemctl status postfix
sudo systemctl status dovecot

# Consulter les logs en temps réel
sudo tail -f /var/log/mail.log
sudo tail -f /var/log/mail.err

# Vérifier la queue Postfix
sudo postqueue -p

# Forcer l'envoi de la queue
sudo postqueue -f

# Supprimer tous les messages en queue
sudo postsuper -d ALL

# Tester la configuration Postfix
sudo postfix check

# Tester la configuration Dovecot
sudo doveconf -n

Problèmes Fréquents

Problème Cause Probable Solution
Connection refused port 25 Postfix non démarré ou port bloqué systemctl start postfix / Vérifier firewall
SSL handshake failed Certificat invalide ou expiré Renouveler avec certbot renew
Authentication failed Mauvais mot de passe ou config SASL Vérifier /var/log/auth.log
Emails rejetés SPF/DKIM/DMARC mal configurés Vérifier les enregistrements DNS
Maildir non créé Permissions incorrectes chown -R vmail:vmail /var/mail

Schéma de Résolution

┌─────────────────────────────────────────────────────────────────────────────┐
│                    ARBRE DE DÉCISION - DÉPANNAGE                            │
└─────────────────────────────────────────────────────────────────────────────┘

                           ┌─────────────────┐
                           │ Email ne part   │
                           │   pas ?         │
                           └────────┬────────┘
                                    │
                    ┌───────────────┴───────────────┐
                    ▼                               ▼
           ┌───────────────┐               ┌───────────────┐
           │ Service actif │               │ Service arrêté│
           │    ?          │               │               │
           └───────┬───────┘               └───────┬───────┘
                   │                               │
                   ▼                               ▼
        ┌──────────────────┐            ┌──────────────────┐
        │ Vérifier les     │            │ systemctl start  │
        │ logs mail.log    │            │ postfix          │
        └────────┬─────────┘            └──────────────────┘
                 │
    ┌────────────┼────────────┐
    ▼            ▼            ▼
┌────────┐  ┌────────┐  ┌────────┐
│ Auth   │  │ DNS    │  │ Quota  │
│ Error  │  │ Error  │  │ Error  │
└───┬────┘  └───┬────┘  └───┬────┘
    │           │           │
    ▼           ▼           ▼
┌────────┐  ┌────────┐  ┌────────┐
│Vérifier│  │Vérifier│  │Vérifier│
│password│  │MX, SPF │  │espace  │
│& SASL  │  │DMARC   │  │disque  │
└────────┘  └────────┘  └────────┘

Récapitulatif des Fichiers

┌─────────────────────────────────────────────────────────────────────────────┐
│                    STRUCTURE DES FICHIERS DE CONFIGURATION                  │
└─────────────────────────────────────────────────────────────────────────────┘

/etc/
├── postfix/
│   ├── main.cf              ← Configuration principale Postfix
│   ├── master.cf            ← Services et ports
│   └── main.cf.backup       ← Sauvegarde
│
├── dovecot/
│   ├── dovecot.conf         ← Configuration principale Dovecot
│   └── conf.d/
│       ├── 10-mail.conf     ← Stockage des mails
│       ├── 10-auth.conf     ← Authentification
│       ├── 10-ssl.conf      ← Certificats SSL
│       └── 10-master.conf   ← Services et sockets
│
└── letsencrypt/
    └── live/
        └── mail.votre-domaine.com/
            ├── fullchain.pem    ← Certificat + chaîne
            └── privkey.pem      ← Clé privée

/var/
├── mail/
│   └── vhosts/
│       └── votre-domaine.com/   ← Boîtes mail (Maildir)
│
└── log/
    ├── mail.log             ← Logs principaux
    └── mail.err             ← Erreurs

Annexes

A. Commandes Utiles

# Gestion des services
sudo systemctl {start|stop|restart|status} postfix
sudo systemctl {start|stop|restart|status} dovecot

# Logs
sudo journalctl -u postfix -f
sudo journalctl -u dovecot -f

# Queue
sudo postqueue -p          # Afficher la queue
sudo postsuper -d ALL      # Vider la queue

# Utilisateurs
sudo doveadm user '*'      # Lister les utilisateurs

B. Checklist de Déploiement

  • DNS : Enregistrements A, MX, SPF, DMARC configurés
  • Reverse DNS (PTR) configuré
  • Certificat SSL obtenu et valide
  • Postfix configuré et testé
  • Dovecot configuré et testé
  • Authentification SASL fonctionnelle
  • Firewall : Ports 25, 587, 993, 995 ouverts
  • Test d'envoi et réception réussi
  • Renouvellement automatique du certificat configuré

Join our Discord community server

For any questions, suggestions, or just to chat with the community, join us on Discord!

900+Members