Postfix Configure Client SMTP Authentication ( Smarthost Authentication )

To configure client SMTP authentication (also known as smarthost authentication) in Postfix, follow these steps:

  1. Install the sasl2-bin package if it’s not already installed:
    sudo apt-get install sasl2-bin
  2. Create a new file in /etc/postfix/sasl directory for the authentication credentials. For example:
    sudo nano /etc/postfix/sasl/sasl_passwd

    Add the following line to the file, replacing smtp.gmail.com with the hostname of your smarthost, USERNAME with your email address, and PASSWORD with your email password:

    [smtp.gmail.com]:587 USERNAME@gmail.com:PASSWORD
  3. Set the permissions on the file so that only root can read and write it:
    sudo chmod 600 /etc/postfix/sasl/sasl_passwd
  4. Create a Postfix lookup table for the SASL password file:
    sudo postmap /etc/postfix/sasl/sasl_passwd

    This will create a hashed version of the sasl_passwd file in the same directory (sasl_passwd.db).

  5. Edit the /etc/postfix/main.cf configuration file and add the following lines to enable client SMTP authentication:
    # Enable SASL authentication
    smtp_sasl_auth_enable = yes
    # Path to the saslauthd socket
    smtp_sasl_path = smtpd
    # Set the authentication method
    smtp_sasl_security_options = noanonymous
    # Set the SASL password lookup table
    smtp_sasl_password_maps = hash:/etc/postfix/sasl/sasl_passwd
    # Set the hostname of the smarthost
    relayhost = [smtp.gmail.com]:587

    Note that you should replace smtp.gmail.com with the hostname of your smarthost and the port number with the appropriate value if necessary.

  6. Save and close the main.cf configuration file, then restart the Postfix service:
    sudo systemctl restart postfix

With these configuration changes, your Postfix server should now be able to authenticate with the smarthost using the credentials you have provided in the sasl_passwd file. Any outgoing mail from your server will be relayed through the smarthost using these credentials.

Leave a Comment