Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| linux:postfix [19-11-2014 00:19] – edmc73 | linux:postfix [16-10-2025 07:42] (Version actuelle) – [Utiliser notre postfix comme un serveur relay via le port 587 avec authentification] edmc73 | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| ====== Postfix ====== | ====== Postfix ====== | ||
| + | ===== Fonctionnement de base juste pour envoyer des mails ===== | ||
| + | |||
| + | La config **/ | ||
| + | |||
| + | < | ||
| + | # See / | ||
| + | |||
| + | |||
| + | # Debian specific: | ||
| + | # line of that file to be used as the name. The Debian default | ||
| + | # is / | ||
| + | #myorigin = / | ||
| + | |||
| + | smtpd_banner = $myhostname ESMTP $mail_name (Raspbian) | ||
| + | biff = no | ||
| + | |||
| + | # appending .domain is the MUA's job. | ||
| + | append_dot_mydomain = no | ||
| + | |||
| + | # Uncomment the next line to generate " | ||
| + | # | ||
| + | |||
| + | readme_directory = no | ||
| + | |||
| + | # See http:// | ||
| + | # fresh installs. | ||
| + | compatibility_level = 2 | ||
| + | |||
| + | |||
| + | |||
| + | # TLS parameters | ||
| + | smtpd_tls_cert_file=/ | ||
| + | smtpd_tls_key_file=/ | ||
| + | smtpd_tls_security_level=may | ||
| + | |||
| + | smtp_tls_CApath=/ | ||
| + | smtp_tls_security_level=may | ||
| + | smtp_tls_session_cache_database = btree: | ||
| + | smtpd_use_tls = yes | ||
| + | smtpd_enforce_tls = yes | ||
| + | |||
| + | smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination | ||
| + | myhostname = myserver.edmc73.com | ||
| + | alias_maps = hash:/ | ||
| + | alias_database = hash:/ | ||
| + | canonical_maps = hash:/ | ||
| + | myorigin = / | ||
| + | mydestination = $myhostname, | ||
| + | relayhost = | ||
| + | mynetworks = 127.0.0.0/8 | ||
| + | mailbox_size_limit = 0 | ||
| + | recipient_delimiter = + | ||
| + | inet_interfaces = 127.0.0.1 | ||
| + | inet_protocols = all | ||
| + | |||
| + | </ | ||
| + | |||
| + | J'ai volontairement désactivé tout ce qui est en rapport avec ipv6 car trop compliqué... | ||
| + | |||
| + | J'ai ajouté les options tls et le **canonical_maps** | ||
| + | |||
| + | Modifiez vos aliases en ajoutant à la fin du fichier **/ | ||
| + | root: mon@mail.com | ||
| + | |||
| + | Puis lancer la commande | ||
| + | newaliases | ||
| + | | ||
| + | Créez ou modifiez le fichier **/ | ||
| + | root@myserver | ||
| + | |||
| + | Puis lancer la commande | ||
| + | postmap / | ||
| + | |||
| + | Relancer Postfix | ||
| + | systemctl restart postfix | ||
| + | |||
| + | Tester l' | ||
| + | mail -s "test d'un mail" root <<< | ||
| + | |||
| + | Vérifiez dans les log | ||
| + | vi / | ||
| + | |||
| + | ===== Ce qui suit date ! ===== | ||
| * http:// | * http:// | ||
| * http:// | * http:// | ||
| Ligne 6: | Ligne 89: | ||
| Un super site en français => http:// | Un super site en français => http:// | ||
| + | |||
| + | A voir pour le return-path => https:// | ||
| ===== Configuration ===== | ===== Configuration ===== | ||
| Ligne 188: | Ligne 273: | ||
| Ajouter une signature DKIM à vos emails sortant => http:// | Ajouter une signature DKIM à vos emails sortant => http:// | ||
| + | Un autre tuto très bien détaillé => http:// | ||
| + | |||
| + | |||
| + | ===== SSL / TLS ===== | ||
| + | |||
| + | Ajouter un certificat SSL valide et configurer le TLS. | ||
| + | |||
| + | Utilisons [[linux: | ||
| + | |||
| + | Créez en 1er une config apache qui permet d' | ||
| + | |||
| + | ./cert-auto certonly --rsa-key-size 4096 -d mail.domain.tld --email admin@domain.tld | ||
| + | |||
| + | Bon, je l' | ||
| + | < | ||
| + | Saving debug log to / | ||
| + | Cert not yet due for renewal | ||
| + | |||
| + | You have an existing certificate that has exactly the same domains or certificate name you requested and isn't close to expiry. | ||
| + | (ref: / | ||
| + | |||
| + | What would you like to do? | ||
| + | ------------------------------------------------------------------------------- | ||
| + | 1: Attempt to reinstall this existing certificate | ||
| + | 2: Renew & replace the cert (limit ~5 per 7 days) | ||
| + | ------------------------------------------------------------------------------- | ||
| + | Select the appropriate number [1-2] then [enter] (press ' | ||
| + | Keeping the existing certificate | ||
| + | Created an SSL vhost at / | ||
| + | Deploying Certificate to VirtualHost / | ||
| + | Enabling available site: / | ||
| + | |||
| + | Please choose whether HTTPS access is required or optional. | ||
| + | ------------------------------------------------------------------------------- | ||
| + | 1: Easy - Allow both HTTP and HTTPS access to these sites | ||
| + | 2: Secure - Make all requests redirect to secure HTTPS access | ||
| + | ------------------------------------------------------------------------------- | ||
| + | Select the appropriate number [1-2] then [enter] (press ' | ||
| + | Redirecting vhost in / | ||
| + | |||
| + | ------------------------------------------------------------------------------- | ||
| + | Congratulations! You have successfully enabled https:// | ||
| + | |||
| + | You should test your configuration at: | ||
| + | https:// | ||
| + | ------------------------------------------------------------------------------- | ||
| + | </ | ||
| + | On peut voir ici que certbot modifie votre fichier de conf apache et crée une nouvelle config apache pour **-le-ssl.conf**, | ||
| + | |||
| + | Maintenant ajoutez le code suivant dans votre **main.cf** | ||
| + | < | ||
| + | # logging | ||
| + | smtpd_tls_loglevel = 1 | ||
| + | # Allow use of TLS but make it optional | ||
| + | smtp_use_tls=yes | ||
| + | # Disable SSLv2/3 as they are vulnerable | ||
| + | smtpd_tls_protocols = !SSLv2, !SSLv3 | ||
| + | smtp_tls_protocols = !SSLv2, !SSLv3 | ||
| + | # Insist on stronger ciphers | ||
| + | smtpd_tls_ciphers = high | ||
| + | smtp_tls_ciphers = high | ||
| + | # keys | ||
| + | smtp_tls_cert_file = / | ||
| + | smtp_tls_key_file = / | ||
| + | </ | ||
| + | Restartez votre postfix | ||
| + | service postfix restart | ||
| + | |||
| + | et voila :) | ||
| + | * doc plus poussé => http:// | ||
| + | |||
| + | ===== Recevoir des mails directement dans une petite interface web de consultation uniquement ===== | ||
| + | |||
| + | Concrètement, | ||
| + | |||
| + | Installer **maildev** -> https:// | ||
| + | |||
| + | Je commence par ajouter une entrée DNS de type MX | ||
| + | toto.com IN MX 10 mon_serveur_smtp.com | ||
| + | |||
| + | J' | ||
| + | noreply@toto.com smtp: | ||
| + | |||
| + | On hash le fichier | ||
| + | postmap / | ||
| + | |||
| + | On modifie le fichier **/ | ||
| + | < | ||
| + | # prise en compte du fichier de transport | ||
| + | transport_maps = hash:/ | ||
| + | |||
| + | # on dit que si un mail vient de ce domaine, on ne cherche pas un user en local, on utilise le fichier de transport pour savoir ce qu'on en fait | ||
| + | relay_domains = toto.com | ||
| + | </ | ||
| + | |||
| + | On restart postfix | ||
| + | systemctl restart postfix | ||
| + | |||
| + | On consulte le journal en temps réel | ||
| + | journactl -xef -u postfix* | ||
| + | |||
| + | Et voila, on recevra directement dans maildev les mails adressés à noreply@toto.com ! | ||
| + | |||
| + | ===== Utiliser notre postfix comme un serveur relay via le port 587 avec authentification ===== | ||
| + | |||
| + | Dans l' | ||
| + | |||
| + | Le port 587 est géré par le service " | ||
| + | |||
| + | < | ||
| + | submission inet n | ||
| + | -o syslog_name=postfix/ | ||
| + | -o smtpd_tls_security_level=encrypt | ||
| + | -o smtpd_sasl_auth_enable=yes | ||
| + | </ | ||
| + | |||
| + | Configuration dans **/ | ||
| + | < | ||
| + | # --- Paramètres SASL (avec Cyrus) --- | ||
| + | smtpd_sasl_auth_enable = yes | ||
| + | smtpd_sasl_security_options = noanonymous | ||
| + | smtpd_sasl_local_domain = $myhostname | ||
| + | # Indique à Postfix d' | ||
| + | smtpd_sasl_type = cyrus | ||
| + | # Chemin vers le fichier de configuration de l' | ||
| + | smtpd_sasl_path = smtpd | ||
| + | |||
| + | # --- Paramètres TLS (toujours obligatoires) --- | ||
| + | smtpd_use_tls = yes | ||
| + | smtpd_tls_security_level = encrypt | ||
| + | smtpd_tls_cert_file = / | ||
| + | smtpd_tls_key_file = / | ||
| + | </ | ||
| + | |||
| + | Vous devez dire à l' | ||
| + | |||
| + | Créez le fichier **/ | ||
| + | |||
| + | mkdir / | ||
| + | vi / | ||
| + | |||
| + | Ajoutez le contenu suivant : | ||
| + | |||
| + | pwcheck_method: | ||
| + | auxprop_plugin: | ||
| + | mech_list: plain login | ||
| + | |||
| + | '' | ||
| + | '' | ||
| + | |||
| + | Maintenant pour générer le fichier de mot de passe utilisé par l' | ||
| + | |||
| + | Debian | ||
| + | apt install sasl2-bin | ||
| + | Red Hat | ||
| + | dnf install cyrus-sasl-plain | ||
| + | |||
| + | L' | ||
| + | |||
| + | Créer un utilisateur | ||
| + | saslpasswd2 -c -u toto.com toto | ||
| + | Saisissez ensuite le mot de passe. Ceci créera un utilisateur toto@toto.com | ||
| + | |||
| + | Mettre à jour le mot de passe | ||
| + | saslpasswd2 -u toto.com toto | ||
| + | Supprimer l' | ||
| + | saslpasswd2 -d -u toto.com toto | ||
| + | Lister les utilisateurs | ||
| + | sasldblistusers2 | ||
| + | |||
| + | Afin que postfix puisse lire le fichier **/ | ||
| + | adduser postfix sasl | ||
| + | systemctl restart postfix | ||
| + | |||
| + | On vérifie | ||
| + | < | ||
| + | ss -tlpn | grep 587 | ||
| + | LISTEN 0 100 0.0.0.0: | ||
| + | </ | ||
| + | |||
| + | Dernière étape, comme postfix tourne en chroot (à vérifier dans master.cf) \\ | ||
| + | Modifier le fichier **/ | ||
| + | < | ||
| + | # Example for chroot Postfix users: "-c -m / | ||
| + | # Example for non-chroot Postfix users: "-c -m / | ||
| + | # | ||
| + | # To know if your Postfix is running chroot, check / | ||
| + | # If it has the line "smtp inet n - y - - smtpd" or "smtp inet n - - - - smtpd" | ||
| + | # then your Postfix is running in a chroot. | ||
| + | # If it has the line "smtp inet n - n - - smtpd" then your Postfix is NOT | ||
| + | # running in a chroot. | ||
| + | OPTIONS=" | ||
| + | </ | ||
| + | |||
| + | Postfix ne pourra pas lire non plus le fichier / | ||
| + | cp / | ||
| + | chmod 640 / | ||
| + | chown root:sasl / | ||
| + | systemctl restart postfix | ||
| + | |||
| + | Jusque là, tout semble fonctionner, | ||
| + | < | ||
| + | (host gmail-smtp-in.l.google.com[66.102.1.27] said: | ||
| + | 550-5.7.26 Your email has been blocked because the sender is unauthenticated. | ||
| + | 550-5.7.26 Gmail requires all senders to authenticate with either SPF or DKIM. | ||
| + | 550-5.7.26 | ||
| + | 550-5.7.26 | ||
| + | 550-5.7.26 | ||
| + | 550-5.7.26 | ||
| + | 550-5.7.26 | ||
| + | 550-5.7.26 | ||
| + | 550 5.7.26 | ||
| + | </ | ||