How to configure Postfix relayhost (smarthost) to send eMail using an external smptd

To configure Postfix to use an external SMTP server as a relayhost (smarthost), you can use the following steps:

  1. Edit the Postfix configuration file:
# nano /etc/postfix/main.cf
  1. 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.

  1. 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
  1. Create the SASL password file:
# nano /etc/postfix/sasl_passwd
  1. Add the following line, replacing smtp.example.com and user@example.com with your SMTP server and username:
smtp.example.com user@example.com:password
  1. Secure the SASL password file:
# chmod 600 /etc/postfix/sasl_passwd
# postmap /etc/postfix/sasl_passwd
  1. 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.

Leave a Comment