Postfix

From Leo's Notes
Last edited on 8 December 2022, at 20:45.

Mail relay configuration

Relay host

To use Postfix as a mail relay server, edit the /etc/postfix/main.cf configuration file and set the relayhost parameter to the SMTP sever and port number.

relayhost = [smtp.example.com]:587

Relay authentication

If the SMTP server requires authentication, add the following lines to main.cf:

smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/password

The postfix password file should be created with the following line. Make sure the first column matches the relay host value defined in the main.cf file without the port number.

[smtp.example.com] username@domain.com:my-password-goes-here

Update the password.db file that postfix uses by running:

# postmap hash:/etc/postfix/password

Restart Postfix to apply these changes.

Relay TLS

For servers that require TLS, set the following in main.cf:

smtp_use_tls = yes

This assumes that smtp.example.com accepts TLS encrypted SMTP connections via 587.

Restart Postfix to apply these changes.

Tasks

Sending email messages

To send a HTML message:

$ (
    echo "To: user@example.com"
    echo "Subject: HTML test"
    echo "Content-Type: text/html"
    echo
    cat email-message.html
) | sendmail.postfix -t

Troubleshooting

550 5.7.60 SMTP; Client does not have permissions to send as this sender

When trying to send an email, postfix bounces the message with the following error message:

<user@domain.ca>: host smtp.domain.ca[136.159.X.X] said: 550 5.7.60
    SMTP; Client does not have permissions to send as this sender (in reply to
    end of DATA command)

If your Postfix server uses the same credentials as the 'From' address in the email message, you can add the following configuration in your /etc/postfix/main.cf file:

canonical_classes = envelope_sender
canonical_maps = regexp:/etc/postfix/canonical

Create /etc/postfix/canonical and add your SMTP login email address after two slashes.

// username@domain.com

Restart Postfix to apply these changes.

Emails sent via this Postfix server will now be sent from the address defined in /etc/postfix/canonical.

See Also