Postfix: relaying through another mailserver
Translation of the original in Catalan. Read it in: CatalàCastellano
In this article Set Up Postfix For Relaying Emails Through Another Mailserver from HowtoForge it is explained how to configure a Postfix to do relaying through an external server. In other words, so that the mail server (MTA) always sends the emails through another mail server (MTA) via SMTP. Perhaps the most interesting thing is that it explains how to do it through an authenticated SMTP.
Trying to summarise the steps explained in the article mentioned.
In the example we will relay through the server smtp.example.com. Apart from using the postconf command to do this, we can also edit the /etc/postfix/main.cf file and add the commands indicated between quotes.
postconf -e 'relayhost = smtp.example.com'
postconf -e 'smtp_sasl_auth_enable = yes'
postconf -e 'smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd'
postconf -e 'smtp_sasl_security_options ='
We will save the user and the password to use against the smtp.example.com server in the /etc/postfix/sasl_passwd file. This file has to be owned by the root user and nobody else should have access to it (perms: 600). Finally we create its .db file.
echo "smtp.example.com someuser:howtoforge" > /etc/postfix/sasl_passwd
chown root:root /etc/postfix/sasl_passwd
chmod 600 /etc/postfix/sasl_passwd
postmap /etc/postfix/sasl_passwd
Finally you only have to restart postfix:
/etc/init.d/postfix restart