Setup Postfix with SMTP-AUTH over SASL2 – Complete Guide

postfixsaslauthdsmtpsmtp-authUbuntu

Hello,

I spent the last few days trying to setup Postfix with SASLDB to send emails from my application over SMTP on Ubuntu Server 15.04. I searched, read and tested a lot about it but I can't get it to work. The Postfix and the mail servers are new to me so I hope someone can help me.

The last thing I tried is the following:

  1. Got a clean install of Ubuntu Server 15.04 x64.

  2. Run this script to install and configure Postfix, SASL AUTH:
    https://gist.github.com/richarddong/2634350

  3. Fix SASLAUTHD to work with chrooted Postfix by this (3. and 4. paragraphs):
    https://github.com/webmin/webmin/issues/58#issuecomment-22985720

    To fix connect() : No such file or directory error by the testsaslauthd command.

  4. I created an user with saslpasswd2 -c -u example.com username.

    Verified it successfully with sasldblistusers2, then tested it with:

    • testsaslauthd -u username@example.com -p password

    • testsaslauthd -u username -p password -r example.com

    • testsaslauthd -u username@example.com -p password -s smtp

    • testsaslauthd -u username -p password -r example.com -s smtp

    • testsaslauthd -u username -p password

    But all of these returned with: 0: NO "authentication failed".

    It accepted only the root user and password, like testsaslauthd -u root -p password.

  5. I checked the configuration and found out it's not using the SASLDB, so I followed this:
    https://serverfault.com/a/547851/317421

    After the SASL, Postfix configuration the results were the same as I wrote above.

    I tried the root user with telnet localhost 25, connected, then AUTH PLAIN base64string, where base64string generated by:

    perl -MMIME::Base64 -e 'print encode_base64("\000root\000password");'

    But returned with 535 5.7.8 Error: authentication failed: generic failure.

This is where I'm now.

Of course I restarted Postfix and SASLAUTHD between these steps.

I tried rebooting the system too but nothing changed.

If someone would be so kind and help me to setup this or got a script for this that would be great!

Best Answer

If anyone got the same error this maybe save you from hours of searching.

In order to use sasldb you need to change the MECHANISMS="pam" line to MECHANISMS="sasldb" in the file /etc/default/saslauthd, that was what I missed.

Then restart the saslauthd and the postfix, and it works with the configuration above.