Table des matiรจres
- Introduction et Architecture
- Prรฉrequis
- Installation des paquets
- Configuration DNS
- Configuration de Postfix
- Configuration de Dovecot
- Sรฉcurisation avec SSL/TLS
- Authentification SASL
- Tests et Validation
- 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