Configure Postfix for authenticated Simple Mail Transfer Protocol (SMTP)

Postfix can be configured to relay mail for users at remote locations with a valid username and password combination. Following this guide will allow Authenticated SMTP and passwords to be sent in plain text. A secure transport layer should be implemented to ensure that usernames and passwords can not be eavesdropped while in transit.

Authenticated SMTP requires users who are not in the “mynetwork” directive within /etc/postfix/ to supply a valid username and password before the mail server will forward mail.

This configuration requires Postfix to be installed and be configured to accept incoming mail on an Internet facing interface.

  1. Open /etc/postfix/ with your editor and add the line smtpd_sasl_auth_enable = yes
    smtpd_sasl_auth_enable = yes

    This line informs Postfix to enable SMTP AUTH when users not in the mynetwork directive attempt to send mail using this Postfix mail server to users not in the domain which Postfix has been configured to listen on.

  2. Also in /etc/postfix/, add smtpd_sasl_security_options=noanonymous

    This disables anonymous style logins for SMTP AUTH. Without this line anyone will be able to use your machine as an open relay.

  3. Again in /etc/postfix/, add the smtpd_recipient_restrictions as specified below:
    smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks,
    reject_unauth_destination, check_relay_domains

    This line sets the restrictions for clients attempting to relay mail through your mail server.

  4. Edit /etc/sysconfig/saslauthd and set the value of MECH (Abbrevition of the word mechanism) to pam:

    Setting this value to pam, sets saslauthd to use the local Plugguable Authentication Modules (PAM) subsystem to validate each username and password.

  5. Ensure that saslauthd will start on boot by adding it to the third and fifth runlevels.
    /sbin/chkconfig --level 35 saslauthd on
  6. Start or restart the saslauthd service:
    /sbin/service saslauthd start
    /sbin/service saslauthd restart
  7. Finally start or restart Postfix:
    /sbin/service postfix start
    /sbin/service postfix restart

The Postfix server should now be started and allow relaying of mail from authenticated clients. You can confirm this by connecting to the mail server using the telnet application.

Most communication with the mail server can be done in plain text, but the authentication information must be encoded in Base64.

You can generate this information by modifying the line below, replacing the username and password with a valid username and password that can be authenticated by the Postfix server.

perl -MMIME::Base64 -e 'print encode_base64("usernameusernamepassword");'

It should produce a string similar to the format below.


Do not loose the generated string as it will be used shortly.

Authentication can be tested by connecting to the mail server with telnet and manually entering the SMTP information.

In the example below the section in bold is what should be typed. Replace the string after AUTH PLAIN with the Base64 string created above

# telnet 25
Connected to (
Escape character is '^]'.
220 ESMTP Postfix
250-SIZE 10240000
AUTH PLAIN dXNlcm5hbWUAdXNlcm5hbWUAcGFzc3dvcmQ= 
235 Authentication successful
221 Bye

The line “250-AUTH PLAIN LOGIN GSSAPI DIGEST-MD5 CRAM-MD5” shows that the Postfix server allows users to authenticate.

For more information, visit the Red Hat Postfix HOWTO.