To configure Postfix to use an external SMTP server as a relayhost (smarthost), you can use the following steps:
- Edit the Postfix configuration file:
nano /etc/postfix/main.cf
- Add or modify the following line:
relayhost = smtp.example.com:587
Replace smtp.example.com
with the hostname or IP address of your SMTP server and 587
with the port number if it’s different.
- Enable SASL authentication (if necessary) by adding the following lines:
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
- Create the SASL password file:
nano /etc/postfix/sasl_passwd
- Add the following line, replacing
smtp.example.com
anduser@example.com
with your SMTP server and username:
smtp.example.com user@example.com:password
- Secure the SASL password file:
chmod 600 /etc/postfix/sasl_passwd
postmap /etc/postfix/sasl_passwd
- Restart the Postfix service:
# service postfix restart
That’s it! Postfix is now configured to use the external SMTP server as a relayhost (smarthost). You can test the configuration by sending a test email from the command line using the “sendmail” command.