Annexes:ConfPostfix

De WikiFr_dbSQWare
Révision datée du 7 juin 2024 à 14:37 par Ymauger (discussion | contributions) (Configurations supplémentaires)
Aller à : navigation, rechercher

Ici nous vous proposerons deux approches de la configuration pour l'envoi de mails, si jamais vous avez vos méthodes ou habitudes en interne ne les changez pas.
Pour ces deux configurations utiliseront Postfix et Sendmail pour l'envoi de mails
'Site principal Postfix'.

Installation de Postfix et Sendmail

Cas de la machine dbSQWare

Si vous avez choisi d'utiliser la vmsqwarebox ou suivi notre guide d'installation d'un socle dbSQWare vous avez déjà les paquets installés. Une mise à jour suffira :

dbsqware@vmsqwarebox:/home/dbsqware $ sudo dnf update

Cas d'un serveur linux

D'un système linux à l'autre l'installation peut varier ici nous prenons une machine Rocky Linux 9

[admin@RockyLinux9 ~]#  sudo dnf update

[admin@RockyLinux9 ~]#  sudo dnf install postfix sendmail
Last metadata expiration check: 0:16:31 ago on Thu 06 Jun 2024 03:29:07 AM EDT.
Dependencies resolved.
===========================================================================================================================================================================================================
 Package                                        Architecture                                  Version                                               Repository                                        Size
===========================================================================================================================================================================================================
Installing:
 postfix                                          x86_64                                       2:3.5.9-24.el9                                        appstream                                       1.4 M
 sendmail                                         x86_64                                       8.16.1-11.el9                                         appstream                                       742 k
Installing dependencies:
 cyrus-sasl                                       x86_64                                       2.1.27-21.el9                                         baseos                                           71 k
 procmail                                         x86_64                                       3.22-56.el9                                           appstream                                       178 k
 tinycdb                                          x86_64                                       0.78-18.el9                                           appstream                                        33 k

Transaction Summary
===========================================================================================================================================================================================================
Install  5 Packages

Total download size: 2.4 M
Installed size: 6.6 M
Is this ok [y/N]:y
Downloading Packages:
(1/5): postfix-3.5.9-24.el9.x86_64.rpm                                                                                                                                     3.6 MB/s | 1.4 MB     00:00
(2/5): cyrus-sasl-2.1.27-21.el9.x86_64.rpm                                                                                                                                 180 kB/s |  71 kB     00:00
(3/5): tinycdb-0.78-18.el9.x86_64.rpm                                                                                                                                      144 kB/s |  33 kB     00:00
(4/5): procmail-3.22-56.el9.x86_64.rpm                                                                                                                                     143 kB/s | 178 kB     00:01
(5/5): sendmail-8.16.1-11.el9.x86_64.rpm                                                                                                                                   329 kB/s | 742 kB     00:02

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                      2.1 MB/s | 1.4 MB     00:00
[..]
Complete!

Cas d'un serveur Windows avec Cygwin


Attention.png
Warning:
Actuellement le paquet postfix pour Cygwin ne semble pas fonctionner..


Mise en place


Note.png
Note:
Nous ne vous proposons que des cas avec envois de mails via une connexion authentifiée.


Approche 1


Information.png
Information:
Dans ce cas là chaque serveur se connecte à un relais externe.

Configuration générale de postfix

Variables à modifier dans main.cf :

[admin@RockyLinux9 ~]#  vi /etc/postfix/main.cf
...
myhostname = votre_hostname
mydomain = votre_domain.tld
relayhost  =   [votre.relais.externe]:numero_de_port

A ajouter à la fin du fichier :

# enable SASL authentication
smtp_sasl_auth_enable = yes
# disallow methods that allow anonymous authentication.
smtp_sasl_security_options = noanonymous
# where to find sasl_passwd
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
# Enable STARTTLS encryption
smtp_use_tls = yes

Si vous avez besoin de certificats, ajoutez également :

# where to find CA certificates
#smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

Credentials pour l'authentification sur le relais

Il faut donner à postfix vos crédentials de connexions chez votre provider de messagerie

[admin@RockyLinux9 ~]#  vi /etc/postfix/sasl_passwd
[votre.relais.externe] username:password

Il faut notifier postfix de cette nouvelle "route" de messagerie

postmap /etc/postfix/sasl_passwd

Configurations supplémentaires

Utiliser toujours la même adresse d'envoi pour les mails (MAIL_FROM_ADRESS) quelque soit l'émetteur réel sur cette machine (utilisateurs ou services locaux) :

[admin@RockyLinux9 ~]#  vi /etc/postfix/canonical
[..]
#                                                                   CANONICAL(5)
/.+/    sender@domain.tld

Si vous regardez le status de postfix lors de l'envoie de mail

admin@RockyLinux9:/etc/postfix $ sudo systemctl status postfix.service
● postfix.service - Postfix Mail Transport Agent
     Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; preset: disabled)
     Active: active (running) since Fri 2024-06-07 11:41:37 CEST; 41s ago
    Process: 3396098 ExecStartPre=/usr/sbin/restorecon -R /var/spool/postfix/pid (code=exited, status=0/SUCCESS)
    Process: 3396099 ExecStartPre=/usr/libexec/postfix/aliasesdb (code=exited, status=0/SUCCESS)
    Process: 3396101 ExecStartPre=/usr/libexec/postfix/chroot-update (code=exited, status=0/SUCCESS)
    Process: 3396102 ExecStart=/usr/sbin/postfix start (code=exited, status=0/SUCCESS)
   Main PID: 3396170 (master)
      Tasks: 9 (limit: 11099)
     Memory: 14.2M
        CPU: 1.038s
     CGroup: /system.slice/postfix.service
             ├─3396170 /usr/libexec/postfix/master -w
             ├─3396171 pickup -l -t unix -u
             ├─3396172 qmgr -l -t unix -u
             ├─3397501 smtpd -n smtp -t inet -u -o stress=
             ├─3397502 proxymap -t unix -u
             ├─3397503 tlsmgr -l -t unix -u
             ├─3397504 trivial-rewrite -n rewrite -t unix -u
             ├─3397505 cleanup -z -t unix -u
             └─3397507 smtp -t unix -u

Jun 07 11:41:37 RockyLinux9 postfix/master[3396170]: daemon started -- version 3.5.9, configuration /etc/postfix
Jun 07 11:41:37 RockyLinux9 systemd[1]: Started Postfix Mail Transport Agent.
Jun 07 11:42:07 RockyLinux9 postfix/smtpd[3397501]: connect from localhost[127.0.0.1]
Jun 07 11:42:07 RockyLinux9 postfix/smtpd[3397501]: 2CAA182008D: client=localhost[127.0.0.1]
Jun 07 11:42:07 RockyLinux9 postfix/cleanup[3397505]: 2CAA182008D: message-id=<202406070942.4579g7WD3397500@RockyLinux9.dom.local>
Jun 07 11:42:07 RockyLinux9 postfix/cleanup[3397505]: 2CAA182008D: replace: header From: admin@RockyLinux9.dom.local from localhost[127.0.0.1]; from=<sender@domain.tld> to=<destinataire>
[..]

L'expéditeur local du mail admin@RockyLinux9.dom.local est remplacé par celui noté dans le fichier canonical

Approche 2


Information.png
Information:
Dans ce cas là ; Un de vos serveurs se connecte à un relais externe, les autres serveur l'utilisent comme RELAYHOST.


Configuration du relais interne


Un seul serveur va se connecter à un fournisseur de messagerie avec une connexion sécurisée (comme dans l'approche 1), par contre tous les autres serveurs enverrons leurs mails en local sur cette machine.

Au niveau du réseau vous aurez donc qu'un seule connexion sortante à gérer !

Ici, nous allons appliquer cette configuration à la machine dbSQWare.

Configuration générale de postfix

Variables à modifier dans main.cf :

dbsqware@vmsqwarebox:/home/dbsqware $  vi /etc/postfix/main.cf
...
myhostname = votre_hostname
mydomain = votre_domain.tld
relayhost  =   [votre.relais.externe]:numero_de_port

A ajouter à la fin du fichier :

# enable SASL authentication
smtp_sasl_auth_enable = yes
# disallow methods that allow anonymous authentication.
smtp_sasl_security_options = noanonymous
# where to find sasl_passwd
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
# Enable STARTTLS encryption
smtp_use_tls = yes

Si vous avez besoin de certificats, ajoutez également :

# where to find CA certificates
#smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
Credentials pour l'authentification sur le relais

Il faut donner à postfix vos crédentials de connexions chez votre provider de messagerie

dbsqware@vmsqwarebox:/home/dbsqware $  vi /etc/postfix/sasl_passwd
[votre.relais.externe] username:password

Il faut notifier postfix de cette nouvelle "route" de messagerie

postmap /etc/postfix/sasl_passwd
Configurations supplémentaires

Utiliser toujours la même adresse d'envoi pour les mails (MAIL_FROM_ADRESS) quelque soit l'émetteur réel de cette machine (utilisateurs ou services locaux) :

dbsqware@vmsqwarebox:/home/dbsqware $  vi /etc/postfix/canonical
[..]
#                                                                   CANONICAL(5)
/.+/    sender@domain.tld

Utiliser toujours la même adresse d'envoi pour les mails (MAIL_FROM_ADRESS) quelque soit l'émetteur réel (utilisateurs ou services distants) :

dbsqware@vmsqwarebox:/home/dbsqware $  vi /etc/postfix/header_checks
[..]
#                                                               HEADER_CHECKS(5)
/From:.*/ REPLACE From: sender@dbsqware.org

Si vous regardez le status de postfix lors de l'envoie de mail

dbsqware@vmsqwarebox:/etc/postfix $ sudo systemctl status postfix.service
● postfix.service - Postfix Mail Transport Agent
     Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; preset: disabled)
     Active: active (running) since Fri 2024-06-07 11:41:37 CEST; 41s ago
    Process: 3396098 ExecStartPre=/usr/sbin/restorecon -R /var/spool/postfix/pid (code=exited, status=0/SUCCESS)
    Process: 3396099 ExecStartPre=/usr/libexec/postfix/aliasesdb (code=exited, status=0/SUCCESS)
    Process: 3396101 ExecStartPre=/usr/libexec/postfix/chroot-update (code=exited, status=0/SUCCESS)
    Process: 3396102 ExecStart=/usr/sbin/postfix start (code=exited, status=0/SUCCESS)
   Main PID: 3396170 (master)
      Tasks: 9 (limit: 11099)
     Memory: 14.2M
        CPU: 1.038s
     CGroup: /system.slice/postfix.service
             ├─3396170 /usr/libexec/postfix/master -w
             ├─3396171 pickup -l -t unix -u
             ├─3396172 qmgr -l -t unix -u
             ├─3397501 smtpd -n smtp -t inet -u -o stress=
             ├─3397502 proxymap -t unix -u
             ├─3397503 tlsmgr -l -t unix -u
             ├─3397504 trivial-rewrite -n rewrite -t unix -u
             ├─3397505 cleanup -z -t unix -u
             └─3397507 smtp -t unix -u

Jun 07 11:41:37 vmsqwarebox postfix/master[3396170]: daemon started -- version 3.5.9, configuration /etc/postfix
Jun 07 11:41:37 vmsqwarebox systemd[1]: Started Postfix Mail Transport Agent.
Jun 07 11:42:07 vmsqwarebox postfix/smtpd[3397501]: connect from localhost[127.0.0.1]
Jun 07 11:42:07 vmsqwarebox postfix/smtpd[3397501]: 2CAA182008D: client=localhost[127.0.0.1]
Jun 07 11:42:07 vmsqwarebox postfix/cleanup[3397505]: 2CAA182008D: message-id=<202406070942.4579g7WD3397500@vmsqwarebox.dom.local>
Jun 07 11:42:07 vmsqwarebox postfix/cleanup[3397505]: 2CAA182008D: replace: header From: dbsqware@vmsqwarebox.dom.local from localhost[127.0.0.1]; from=<sender@domain.tld> to=<destinataire>
[..]

L'expéditeur local du mail dbsqware@vmsqwarebox.dom.local est remplacé par celui noté dans le fichier canonical



Note.png
Note:
vous pouvez également réaliser cette configuration sur un autre serveur que la vmsqwarebox.


Configuration des clients du relais


Note.png
Note:
Si vous avez déjà un relayhost en interne, appliquez cette configuration à tous les serveurs concernés y compris la vmsqwarebox et en utilisant ce serveur comme RELAYHOST.


Tests et validation

la commande -SenReport !

systemctl status postfix

dbsqware@vmsqwarebox:/etc/postfix $ sudo systemctl status postfix
● postfix.service - Postfix Mail Transport Agent
     Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; preset: disabled)
     Active: active (running) since Mon 2024-05-13 09:22:05 CEST; 3 weeks 3 days ago
    Process: 948 ExecStartPre=/usr/sbin/restorecon -R /var/spool/postfix/pid (code=exited, status=0/SUCCESS)
    Process: 957 ExecStartPre=/usr/libexec/postfix/aliasesdb (code=exited, status=0/SUCCESS)
    Process: 1047 ExecStartPre=/usr/libexec/postfix/chroot-update (code=exited, status=0/SUCCESS)
    Process: 1061 ExecStart=/usr/sbin/postfix start (code=exited, status=0/SUCCESS)
   Main PID: 1645 (master)
      Tasks: 9 (limit: 11099)
     Memory: 18.5M
        CPU: 59.255s
     CGroup: /system.slice/postfix.service
             ├─   1645 /usr/libexec/postfix/master -w
             ├─   1647 qmgr -l -t unix -u
             ├─  30563 tlsmgr -l -t unix -u
             ├─3202794 pickup -l -t unix -u
             ├─3209180 smtpd -n smtp -t inet -u -o stress=
             ├─3209181 proxymap -t unix -u
             ├─3209182 trivial-rewrite -n rewrite -t unix -u
             ├─3209183 cleanup -z -t unix -u
             └─3209184 smtp -t unix -u

Jun 06 08:55:49 vmsqwarebox postfix/smtp[3188686]: 57E1D82008C: to=<yohann.mauger@dbsqware.com>, relay=mail.gandi.net[217.70.178.9]:587, delay=0.49, delays=0.03/0.1/0.04/0.32, dsn=2.0.0, status=sent (25>
Jun 06 08:55:49 vmsqwarebox postfix/qmgr[1647]: 57E1D82008C: removed
Jun 06 11:36:27 vmsqwarebox postfix/smtpd[3209180]: connect from srvyohdbpg01.dbyoh.local[192.168.231.124]
Jun 06 11:36:27 vmsqwarebox postfix/smtpd[3209180]: 7584A82008C: client=srvyohdbpg01.dbyoh.local[192.168.231.124]
Jun 06 11:36:27 vmsqwarebox postfix/cleanup[3209183]: 7584A82008C: replace: header From: postgres@srvyohdbpg01 from srvyohdbpg01.dbyoh.local[192.168.231.124]; from=<sender@dbsqware.org> to=<yohann.mauge>
Jun 06 11:36:27 vmsqwarebox postfix/cleanup[3209183]: 7584A82008C: message-id=<20240606093708.C35531A06671@srvyohdbpg01.localdomain>
Jun 06 11:36:27 vmsqwarebox postfix/qmgr[1647]: 7584A82008C: from=<sender@dbsqware.org>, size=12419, nrcpt=1 (queue active)
Jun 06 11:36:27 vmsqwarebox postfix/smtpd[3209180]: disconnect from srvyohdbpg01.dbyoh.local[192.168.231.124] ehlo=2 starttls=1 mail=1 rcpt=1 data=1 quit=1 commands=7
Jun 06 11:36:27 vmsqwarebox postfix/smtp[3209184]: 7584A82008C: to=<yohann.mauger@dbsqware.com>, relay=mail.gandi.net[217.70.178.9]:587, delay=0.43, delays=0.02/0.11/0.04/0.26, dsn=2.0.0, status=sent (2>
Jun 06 11:36:27 vmsqwarebox postfix/qmgr[1647]: 7584A82008C: removed

dbsqware@vmsqwarebox:/etc/postfix $