Serveur mail

Voici une procédure complète pour un serveur mail professionnel basé sur
Postfix + Dovecot + DKIM + SPF + SSL (Let’s Encrypt)
👉 Ubuntu 22.04 / Debian 12 (référence pro, stable).


🧱 Architecture

  • Postfix : SMTP (envoi/réception)
  • Dovecot : IMAP + Authentification
  • OpenDKIM : DKIM
  • SPF / DMARC : DNS
  • TLS/SSL : Let’s Encrypt
  • Maildir : stockage des mails

1️⃣ Prérequis indispensables

DNS (AVANT TOUT)

Pour le domaine example.com :

Type Nom Valeur
A mail.example.com IP_SERVEUR
MX example.com mail.example.com
PTR (reverse DNS) IP_SERVEUR mail.example.com

⚠️ Sans PTR, tes mails iront en spam


2️⃣ Installation des paquets

sudo apt update
sudo apt install postfix dovecot-imapd dovecot-pop3d \
opendkim opendkim-tools certbot mailutils

Pendant Postfix :

  • Type : Internet Site
  • Nom du courrier : example.com

3️⃣ Configuration Postfix

/etc/postfix/main.cf

myhostname = mail.example.com
mydomain = example.com
myorigin = $mydomain
inet_interfaces = all
inet_protocols = ipv4mydestination = $myhostname, localhost.$mydomain, localhost, $mydomainhome_mailbox = Maildir/smtpd_tls_cert_file=/etc/letsencrypt/live/mail.example.com/fullchain.pem
smtpd_tls_key_file=/etc/letsencrypt/live/mail.example.com/privkey.pem
smtpd_use_tls=yessmtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yessmtpd_recipient_restrictions =
permit_sasl_authenticated,
permit_mynetworks,
reject_unauth_destination

4️⃣ Configuration Dovecot

Maildir

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

mail_location = maildir:~/Maildir

Authentification SMTP

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

service auth {
unix_listener /var/spool/postfix/private/auth {
mode = 0660
user = postfix
group = postfix
}
}

SSL

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

ssl = required
ssl_cert = </etc/letsencrypt/live/mail.example.com/fullchain.pem
ssl_key = </etc/letsencrypt/live/mail.example.com/privkey.pem

5️⃣ Certificat SSL Let’s Encrypt

sudo certbot certonly --standalone -d mail.example.com

Renouvellement auto :

sudo crontab -e
0 3 * * * certbot renew --quiet

6️⃣ DKIM (OpenDKIM)

Génération de clé

sudo mkdir -p /etc/opendkim/keys/example.com
sudo opendkim-genkey -D /etc/opendkim/keys/example.com -d example.com -s mail
sudo chown -R opendkim:opendkim /etc/opendkim

Configuration OpenDKIM

/etc/opendkim.conf

Domain example.com
KeyFile /etc/opendkim/keys/example.com/mail.private
Selector mail
Socket inet:8891@localhost

Postfix ↔ DKIM

/etc/postfix/main.cf

milter_default_action = accept
milter_protocol = 6
smtpd_milters = inet:localhost:8891
non_smtpd_milters = inet:localhost:8891

7️⃣ DNS DKIM

Dans le DNS :

mail._domainkey.example.com TXT
"v=DKIM1; k=rsa; p=CLÉ_PUBLIQUE"

👉 clé publique dans mail.txt


8️⃣ SPF (DNS)

example.com TXT
"v=spf1 mx ip4:IP_SERVEUR -all"

9️⃣ DMARC (DNS)

_dmarc.example.com TXT
"v=DMARC1; p=quarantine; rua=mailto:postmaster@example.com"

🔟 Création d’un utilisateur mail

sudo adduser user

Mail stocké :

/home/user/Maildir

🔄 Redémarrage des services

sudo systemctl restart postfix dovecot opendkim

✅ Tests indispensables

Envoi local

echo "Test OK" | mail -s "Mail Server" user@example.com

Vérification DKIM/SPF


🔐 Ports à ouvrir (Firewall)

Service Port
SMTP 25
Submission 587
IMAPS 993

Étiquettes :

Les commentaires sont fermés.
Serveur basé en Suisse