Introduction
Postfix : MTA (Mail Transfer Agent), gere l'envoi et la reception SMTP. Dovecot : MDA (Mail Delivery Agent) + IMAP/POP3, permet aux clients (Thunderbird, Outlook) de relever le courrier.
Heberger son mail c'est :
- Beneficier d'une vraie privacy (vs Gmail)
- Avoir des alias illimites
- Pas de tracking, pas de pub
- Mais : reputation IP a soigner, anti-spam a configurer, beaucoup de DNS
Prerequis
- VPS Linux Debian 12 / Ubuntu 24.04
- IP publique avec rDNS configure (CRUCIAL pour la deliverability)
- Nom de domaine (
verycloud.fr) avec acces aux DNS - Acces root
- Port 25 ouvert (verifiez avec votre hebergeur, certains le bloquent par defaut)
Etape 1 : Verifications prealables
# Port 25 ouvert sortant ?
nc -zv smtp.google.com 25
# rDNS configure ?
host VOTRE_IP
# Doit retourner mail.verycloud.fr
Si rDNS pas bon, configurez-le chez votre hebergeur (panel ou ticket).
DNS du domaine : configurez avant tout :
verycloud.fr. MX 10 mail.verycloud.fr.
mail.verycloud.fr. A VOTRE_IP
verycloud.fr. TXT "v=spf1 mx -all"
Etape 2 : Installation Postfix
sudo apt update
sudo apt install -y postfix postfix-mysql
L'installer demande le type :
- Choisir "Internet Site"
- System mail name :
verycloud.fr(sansmail.)
Etape 3 : Configuration Postfix de base
sudo nano /etc/postfix/main.cf
myhostname = mail.verycloud.fr
mydomain = verycloud.fr
myorigin = $mydomain
inet_interfaces = all
inet_protocols = ipv4
mydestination = $myhostname, localhost.$mydomain, localhost
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
home_mailbox = Maildir/
mailbox_command =
smtpd_banner = $myhostname ESMTP
biff = no
append_dot_mydomain = no
# Restrictions anti-spam basiques
smtpd_helo_required = yes
smtpd_helo_restrictions = reject_invalid_helo_hostname, reject_non_fqdn_helo_hostname
smtpd_sender_restrictions = reject_unknown_sender_domain, reject_non_fqdn_sender
smtpd_recipient_restrictions =
permit_mynetworks,
permit_sasl_authenticated,
reject_unauth_destination,
reject_unknown_recipient_domain
# Limites
message_size_limit = 26214400 # 25 MB max
mailbox_size_limit = 0
Etape 4 : TLS pour Postfix
Generez ou utilisez Let's Encrypt :
sudo apt install -y certbot
sudo certbot certonly --standalone -d mail.verycloud.fr
Ajoutez dans main.cf :
# TLS entrant
smtpd_tls_cert_file = /etc/letsencrypt/live/mail.verycloud.fr/fullchain.pem
smtpd_tls_key_file = /etc/letsencrypt/live/mail.verycloud.fr/privkey.pem
smtpd_use_tls = yes
smtpd_tls_security_level = may
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
# TLS sortant
smtp_tls_security_level = may
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtp_tls_loglevel = 1
Etape 5 : SMTP submission (port 587 et 465)
master.cf :
sudo nano /etc/postfix/master.cf
Activez ces blocs :
submission inet n - y - - smtpd
-o syslog_name=postfix/submission
-o smtpd_tls_security_level=encrypt
-o smtpd_sasl_auth_enable=yes
-o smtpd_sasl_type=dovecot
-o smtpd_sasl_path=private/auth
-o smtpd_reject_unlisted_recipient=no
-o smtpd_recipient_restrictions=permit_sasl_authenticated,reject
smtps inet n - y - - smtpd
-o syslog_name=postfix/smtps
-o smtpd_tls_wrappermode=yes
-o smtpd_sasl_auth_enable=yes
-o smtpd_sasl_type=dovecot
-o smtpd_sasl_path=private/auth
-o smtpd_recipient_restrictions=permit_sasl_authenticated,reject
Restart :
sudo systemctl restart postfix
Etape 6 : Installation Dovecot
sudo apt install -y dovecot-imapd dovecot-pop3d dovecot-lmtpd
Etape 7 : Configuration Dovecot
/etc/dovecot/dovecot.conf :
protocols = imap pop3 lmtp
/etc/dovecot/conf.d/10-mail.conf :
mail_location = maildir:~/Maildir
/etc/dovecot/conf.d/10-auth.conf :
disable_plaintext_auth = yes
auth_mechanisms = plain login
/etc/dovecot/conf.d/10-ssl.conf :
ssl = required
ssl_cert = </etc/letsencrypt/live/mail.verycloud.fr/fullchain.pem
ssl_key = </etc/letsencrypt/live/mail.verycloud.fr/privkey.pem
ssl_min_protocol = TLSv1.2
/etc/dovecot/conf.d/10-master.conf (le bloc auth pour Postfix SASL) :
service auth {
unix_listener /var/spool/postfix/private/auth {
mode = 0660
user = postfix
group = postfix
}
}
Restart :
sudo systemctl restart dovecot postfix
Etape 8 : Premier compte mail
Dovecot peut utiliser les comptes systeme. Creez un user :
sudo adduser mathys
Le user existe en Linux. Pour qu'il puisse recevoir du mail :
sudo mkdir -p /home/mathys/Maildir
sudo chown -R mathys:mathys /home/mathys/Maildir
Test envoi (depuis le serveur) :
echo "Hello" | mail -s "Test" [email protected]
ls /home/mathys/Maildir/new/
Si un mail apparait, tout marche cote livraison locale.
Etape 9 : SPF, DKIM, DMARC
SPF : declarez quelles IPs peuvent envoyer pour votre domaine.
DNS :
verycloud.fr. TXT "v=spf1 mx ip4:VOTRE_IP -all"
DKIM : signez vos mails.
sudo apt install -y opendkim opendkim-tools
sudo mkdir -p /etc/opendkim/keys/verycloud.fr
cd /etc/opendkim/keys/verycloud.fr
sudo opendkim-genkey -s mail -d verycloud.fr
sudo chown opendkim:opendkim mail.private
Le fichier mail.txt contient le record DNS a publier :
mail._domainkey.verycloud.fr. TXT "v=DKIM1; h=sha256; k=rsa; p=MIIBIj..."
Configurer opendkim :
sudo nano /etc/opendkim.conf
Syslog yes
UMask 002
Domain verycloud.fr
KeyFile /etc/opendkim/keys/verycloud.fr/mail.private
Selector mail
SOCKET inet:8891@localhost
Mode sv
Integration Postfix :
# /etc/postfix/main.cf
smtpd_milters = inet:localhost:8891
non_smtpd_milters = inet:localhost:8891
milter_default_action = accept
sudo systemctl restart opendkim postfix
DMARC : politique d'action.
_dmarc.verycloud.fr. TXT "v=DMARC1; p=quarantine; rua=mailto:[email protected]"
p=quarantine (mails non conformes -> spam) ou p=reject (rejete) pour stricter.
Etape 10 : Configurer Thunderbird / Outlook
- Serveur entrant :
mail.verycloud.fr, port 993 IMAP SSL/TLS - Serveur sortant :
mail.verycloud.fr, port 587 STARTTLS - Auth : login + mot de passe Linux
Connectez, envoyez, recevez.
Etape 11 : Anti-spam avec Rspamd
Installez Rspamd (voir tuto 40 dedie) pour filtrer le spam entrant :
sudo apt install -y rspamd
Integration Postfix dans main.cf :
smtpd_milters = inet:localhost:11332, inet:localhost:8891
(rspamd sur 11332, opendkim sur 8891)
Etape 12 : Test deliverability
Envoyez un mail vers https://www.mail-tester.com et vous obtiendrez un score sur 10. Cible : 10/10.
Verifiez aussi :
- https://mxtoolbox.com/SuperTool.aspx pour SPF / DKIM / DMARC / Blacklists
- Les logs
/var/log/mail.log
Depannage
Mails rejetes par Gmail / Outlook
Verifiez :
- rDNS configure
- SPF, DKIM, DMARC publies
- IP pas blacklistee (https://mxtoolbox.com/blacklists.aspx)
- Si IP recente, "warm-up" : envoyer progressivement
"Connection refused" sur port 25
Hebergeur bloque le port. OVH, Hetzner et autres bloquent souvent en sortie par defaut. Demandez l'ouverture par ticket.
Auth IMAP echoue
sudo tail -f /var/log/mail.log
sudo journalctl -u dovecot -f
Verifiez disable_plaintext_auth et que vous utilisez bien SSL/TLS.
DKIM ne signe pas
sudo journalctl -u opendkim -f
Verifiez les permissions sur mail.private (opendkim:opendkim 600).
Mail livre dans le dossier wrong
mailbox_command doit etre vide pour Maildir + Dovecot. Si vous utilisez procmail, configurez-le specifiquement.
Commandes utiles
# Postfix
sudo systemctl status postfix
sudo postfix check
sudo postconf -n # config active
sudo postqueue -p # queue
sudo postqueue -f # flush
sudo postsuper -d ALL # vider la queue (danger)
# Dovecot
sudo systemctl status dovecot
sudo doveconf -n
sudo doveadm who # users connectes
sudo doveadm mailbox list -u mathys
# Logs
sudo tail -f /var/log/mail.log
sudo journalctl -u postfix -f
sudo journalctl -u dovecot -f
# Test envoi
echo "body" | mail -s "subject" [email protected]
# Test SMTP en CLI
swaks --to [email protected] --from [email protected] --server mail.verycloud.fr:587 --tls --auth LOGIN --auth-user [email protected]
# DKIM test
echo "test" | opendkim-testmsg -s mail -d verycloud.fr -p /etc/opendkim/keys/verycloud.fr/mail.private
Conclusion
Postfix + Dovecot vous donne :
- Serveur mail complet auto-heberge
- Privacy totale
- Alias et comptes illimites
Limites :
- Setup et maintenance demandeurs
- Reputation IP a soigner (deliverability)
- Pas de webmail integre (ajoutez Roundcube)
Pour aller plus loin :
- Ajoutez Roundcube ou SnappyMail comme webmail
- Pour une approche turnkey, regardez Mailcow (tuto 39)
- Pour de la haute dispo, regardez OpenSMTPD ou Mailu
Ressources
- Documentation Postfix : http://www.postfix.org/documentation.html
- Documentation Dovecot : https://doc.dovecot.org
- OpenDKIM : http://www.opendkim.org
- Mail-tester : https://www.mail-tester.com


















