Postfix en tant que relay

De Linux Server Wiki
Aller à la navigation Aller à la recherche
aptitude install postfix

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 578 (submission)
  • utilisateur permettant d'envoyer le mail : test@otherdomain.tld
  • mot de passe : password

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

echo "relay.domain.tld:587 test@otherdomain.tld:password" > /etc/postfix/smarthost_passwd
chown root:root /etc/postfix/smarthost_passwd
chmod 600 /etc/postfix/smarthost_passwd
postmap /etc/postfix/smarthost_passwd

configuration de postfix :

relayhost = relay.domain.tld:587
smtp_use_tls=yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/smarthost_passwd
smtp_sasl_security_options = noanonymous
/etc/init.d/postfix restart

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

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

/etc/postfix/smarthost_passwd contiendra les associations de cette manière :

sender1@domain1.tld userforsender1@domain1.tld:password
sender2@domain1.tld userforsender2@domain1.tld:password
@domain2.tld userfordomain2@domain2.tld:password

configuration de postfix :

relayhost = relay.domain.tld:587
smtp_use_tls=yes
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
sender1@domain1.tld relay.domain.tld
sender2@domain.tld relay.domain.tld
@domain2.tld relay2.domain.tld
/etc/init.d/postfix restart