Palier 3: Postfix + Dovecot working! Mail test successful with swaks

This commit is contained in:
ayo 2026-06-17 09:54:03 +02:00
commit 4a989bad17
7 changed files with 82 additions and 55 deletions

38
docker-compose.yml Normal file
View file

@ -0,0 +1,38 @@
version: '3.9'
services:
dovecot:
build:
context: .
dockerfile: dovecot/Dockerfile
container_name: mailstack-dovecot
ports:
- "1143:143" # IMAP
- "1993:993" # IMAPS
volumes:
- vmail:/var/mail/vhosts
networks:
- mailstack
postfix:
build:
context: .
dockerfile: postfix/Dockerfile
container_name: mailstack-postfix
ports:
- "1025:25" # SMTP
- "1587:587" # SMTP + AUTH
- "1465:465" # SMTPS
volumes:
- vmail:/var/mail/vhosts
networks:
- mailstack
depends_on:
- dovecot
volumes:
vmail:
networks:
mailstack:
driver: bridge

View file

@ -1,22 +1,17 @@
# Image de base Alpine FROM debian:bookworm-slim
FROM alpine:3.21
# Installer Dovecot (IMAP/POP3) + le module d'authentification RUN apt-get update && apt-get install -y dovecot-core dovecot-imapd
RUN apk add --no-cache dovecot
# --- Utilisateur vmail identique à celui de Postfix (uid/gid 5000) --- RUN mkdir -p /var/mail/vhosts && \
RUN (deluser vmail 2>/dev/null || true) \ useradd -m -u 5000 -d /var/mail/vhosts vmail || true
&& (delgroup vmail 2>/dev/null || true) \
&& addgroup -g 5000 vmail \
&& adduser -D -u 5000 -G vmail -h /var/mail/vhosts vmail \
&& mkdir -p /var/mail/vhosts
# --- Copier nos fichiers de config dans l'image --- COPY ../share/users.txt /tmp/users.txt
COPY dovecot.conf /etc/dovecot/dovecot.conf COPY ../share/dovecot.sh /tmp/dovecot.sh
COPY users /etc/dovecot/users
RUN chmod +x /tmp/dovecot.sh && \
/tmp/dovecot.sh > /etc/dovecot/users && \
rm /tmp/users.txt /tmp/dovecot.sh
# Exposer les ports IMAP
EXPOSE 143 993 EXPOSE 143 993
# Lancer Dovecot au premier plan
CMD ["dovecot", "-F"] CMD ["dovecot", "-F"]

View file

@ -1,43 +1,18 @@
# Image de base Alpine, légère FROM debian:bookworm-slim
FROM alpine:3.21
# Installer Postfix et les outils RUN apt-get update && apt-get install -y postfix mailutils
RUN apk add --no-cache postfix postfix-pcre rsyslog
# --- Utilisateur dédié au stockage des mails virtuels --- COPY ../share/users.txt /tmp/users.txt
# Tous les mails appartiendront à cet utilisateur "vmail" (uid/gid 5000) COPY ../share/postfix.sh /tmp/postfix.sh
# Supprimer le vmail créé par défaut par Postfix, puis recréer le nôtre en uid/gid 5000 COPY postfix/main.cf /etc/postfix/main.cf
RUN (deluser vmail 2>/dev/null || true) \ COPY postfix/entrypoint.sh /entrypoint.sh
&& (delgroup vmail 2>/dev/null || true) \
&& addgroup -g 5000 vmail \
&& adduser -D -u 5000 -G vmail -h /var/mail/vhosts vmail \
&& mkdir -p /var/mail/vhosts/ayoinc.test \
&& chown -R vmail:vmail /var/mail/vhosts
# --- Configuration Postfix de base ---
RUN postconf -e "myhostname = mail.ayoinc.test" \
&& postconf -e "mydomain = ayoinc.test" \
&& postconf -e "myorigin = \$mydomain" \
# Postfix ne gère PAS lui-même notre domaine en "local" : c'est du virtuel
&& postconf -e "mydestination = localhost" \
&& postconf -e "inet_interfaces = all" \
&& postconf -e "inet_protocols = ipv4"
# --- Configuration des boîtes virtuelles --- RUN chmod 644 /etc/postfix/main.cf && \
RUN postconf -e "virtual_mailbox_domains = ayoinc.test" \ chmod +x /tmp/postfix.sh /entrypoint.sh && \
&& postconf -e "virtual_mailbox_base = /var/mail/vhosts" \ /tmp/postfix.sh > /etc/postfix/virtual_mailbox && \
&& postconf -e "virtual_mailbox_maps = lmdb:/etc/postfix/vmailbox" \ postmap /etc/postfix/virtual_mailbox && \
&& postconf -e "virtual_minimum_uid = 5000" \ rm /tmp/users.txt /tmp/postfix.sh
&& postconf -e "virtual_uid_maps = static:5000" \
&& postconf -e "virtual_gid_maps = static:5000"
# --- Déclaration des comptes virtuels (alice & bob) --- EXPOSE 25 587
# Chaque ligne : adresse -> chemin Maildir (le / final = format Maildir)
RUN echo "alice@ayoinc.test ayoinc.test/alice/" > /etc/postfix/vmailbox \
&& echo "bob@ayoinc.test ayoinc.test/bob/" >> /etc/postfix/vmailbox \
&& postmap lmdb:/etc/postfix/vmailbox
# Exposer le port SMTP CMD ["/entrypoint.sh"]
EXPOSE 25
# Lancer Postfix au premier plan
CMD ["postfix", "start-fg"]

4
postfix/entrypoint.sh Executable file
View file

@ -0,0 +1,4 @@
#!/bin/bash
set -e
postfix start
tail -f /dev/null

15
postfix/main.cf Normal file
View file

@ -0,0 +1,15 @@
myhostname = mail.ayoinc.test
myorigin = ayoinc.test
mydestination = localhost
mynetworks = 127.0.0.0/8 [::1]/128
inet_interfaces = all
virtual_mailbox_domains = ayoinc.test
virtual_mailbox_base = /var/mail/vhosts
virtual_mailbox_maps = hash:/etc/postfix/virtual_mailbox
virtual_uid_maps = static:5000
virtual_gid_maps = static:5000
virtual_transport = virtual
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
maillog_file = /dev/stdout

View file

@ -3,4 +3,4 @@
while IFS= read -r email; do while IFS= read -r email; do
username="${email%@*}" username="${email%@*}"
echo "${email}:{PLAIN}${username}" echo "${email}:{PLAIN}${username}"
done < users.txt done < /tmp/users.txt

View file

@ -4,4 +4,4 @@ while IFS= read -r email; do
username="${email%@*}" username="${email%@*}"
domain="${email#*@}" domain="${email#*@}"
echo "${email} ${domain}/${username}/" echo "${email} ${domain}/${username}/"
done < users.txt done < /tmp/users.txt