« Postfix en tant que relay » : différence entre les versions

De Linux Server Wiki
Aller à la navigation Aller à la recherche
Aucun résumé des modifications
Aucun résumé des modifications
Ligne 1 : Ligne 1 :
[[Category:serveur]]
[[Category:serveur]]
[[Category:debian]]
[[Category:debian]]
<pre>aptitude install postfix</pre>
<pre>aptitude install postfix libsasl2-modules </pre>


Configuez le en tant que "internet with smarthost". Dans SMTP Relay Host, entrez l'hostname:port que vous souhaitez utiliser comme smtp sortant.
Configuez le en tant que "internet with smarthost". Dans SMTP Relay Host, entrez l'hostname:port que vous souhaitez utiliser comme smtp sortant.

Version du 14 janvier 2019 à 15:03

aptitude install postfix libsasl2-modules 

Configuez le en tant que "internet with smarthost". Dans SMTP Relay Host, entrez l'hostname:port que vous souhaitez utiliser comme smtp sortant.

Nous allons utiliser les informations suivantes :

  • serveur de relai mail : relay.domain.tld sur le port 587 (submission)
  • utilisateur permettant d'envoyer le mail via le serveur relay.domain.tld : test@otherdomain.tld
  • mot de passe de l'utilisateur sur le serveur relay.domain.tld : password
  • en forçant le chiffrement TLS sans vérifier la chaîne de certification

Configuration simple : relayer tous les mails via un seul relay et un seul compte

Dans /etc/postfix/main.cf :

relayhost = [relay.domain.tld]:587
smtp_use_tls=yes
smtp_tls_security_level = encrypt
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/smarthost_passwd
smtp_sasl_security_options = noanonymous

Dans /etc/postfix/smarthost_passwd :

# Destination           credentials
[relay.domain.tld]:587     test@otherdomain.tld:password 

Appliquez la configuration :

chown root:root /etc/postfix/smarthost_passwd
chmod 600 /etc/postfix/smarthost_passwd
postmap /etc/postfix/smarthost_passwd

Redémarrez postfix pour appliquer les modifications

/etc/init.d/postfix restart

Relayer en fonction du domaine cible, de l'utilisateur envoyant le mail (avec mots de passe différents)

Dans /etc/postfix/main.cf :

relayhost = [relay.domain.tld]:587
smtp_use_tls=yes
smtp_tls_security_level = encrypt
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/smarthost_passwd
smtp_sasl_security_options = noanonymous
smtp_sender_dependent_authentication = yes
sender_dependent_relayhost_maps = hash:/etc/postfix/sender_relay

Dans /etc/postfix/smarthost_passwd :

# Per-sender authentication; see also /etc/postfix/sender_relay.
localuser1@localdomain1 remoteuser:remotepassword
localuser2@localdomain2 remoteuser2:remotepassword2
# Login information for the default relayhost (fallback if no per-sender is found)
[relay.domain.tld]:587     user:password 

Dans /etc/postfix/sender_relay:

# Per-sender provider; see also /etc/postfix/sasl_passwd.
localuser1@localdomain1     [relay2.domain.tld]:587
localuser2@localdomain2     [relay3.domain.tld]:587

Appliquez la configuration :

chown root:root /etc/postfix/smarthost_passwd
chmod 600 /etc/postfix/smarthost_passwd
postmap /etc/postfix/smarthost_passwd
postmap /etc/postfix/sender_relay

En gros :

  • Quand vous envoyez un mail en tant que localuser1@localdomain1, postfix se connecte sur relay2.domain.tld et s'authentifie en tant que remoteuser avec le mot-de-passe remotepassword
  • Quand vous envoyez un mail en tant que localuser2@localdomain2, postfix se connecte sur relay3.domain.tld et s'authentifie en tant que remoteuser2 avec le mot-de-passe remotepassword2
  • Pour les mails provenant de tout autre utilisateur, postfix se connecte sur relay.domain.tld et s'authentifie en tant que userfordomain2@domain2.tld7
  • Quand vous envoyez un mail en tant que nimportequoi@domain2.tld, postfix se connecte sur relay2.domain.tld et s'authentifie en tant que user avec le mot-de-passe password

Redémarrez postfix pour appliquer les modifications

/etc/init.d/postfix restart