Let’s start with the easy part… installing the packages (it’s a debian sarge server):

apt-get install mailutils sasl2-bin

 

Now install the postfix:

sudo apt-get update
sudo DEBIAN_PRIORITY=low apt-get install postfix

To be explicit, these are the settings we’ll use for this guide:

General type of mail configuration?: Internet Site
System mail name ( this is the domain name): example.com (not mail.example.com)
Root and postmaster mail recipient: sammy
Other destinations to accept mail for: $myhostname, example.com, mail.example.com, localhost.example.com, localhost
Force synchronous updates on mail queue?: No
Local networks: 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
Mailbox size limit: 0
Local address extension character: +
Internet protocols to use: all

If you need to ever return to re-adjust these settings, you can do so by typing:

sudo dpkg-reconfigure postfix

Now edit /etc/default/saslauthd:

START=yes
MECHANISMS="pam"

saslauthd is not started after package installation (we’ll do it later)!
Next file to edit is /etc/postfix/sasl/smtpd.conf (you have to create it):

pwcheck_method: saslauthd

Ok, let’s add some lines in /etc/postfix/main.cf to enable SASL:

smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes

smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination

postfix does a chroot so it can’t communicate with saslauthd. This is the tricky part:

rm -r /var/run/saslauthd/
mkdir -p /var/spool/postfix/var/run/saslauthd
ln -s /var/spool/postfix/var/run/saslauthd /var/run
chgrp sasl /var/spool/postfix/var/run/saslauthd
adduser postfix sasl

If you work in a small environment you may want the saslauthd server verifies passwords against the authentication backend /etc/shadow , like this:

% saslauthd -a shadow

You can create a user by :

useradd -d /home/sample_user -g users sample_user
passwd sample_user

Now restart postfix and start saslauthd

/etc/init.d/postfix restart
/etc/init.d/saslauthd start

 

Problem:

1.

Oct 27 22:17:32 computer postfix/smtpd[30787]: warning: SASL authentication failure: Password verification failed
Oct 27 22:17:32 computer postfix/smtpd[30787]: warning: unknown[192.168.0.34]: SASL PLAIN authentication failed: generic failure
Oct 27 22:17:34 computer postfix/smtpd[30787]: warning: SASL authentication failure: cannot connect to saslauthd server: No such file or directory

or

warning: SASL authentication failure: cannot connect to saslauthd server: Too many levels of symbolic links
Solution:

 

Stop both postfix and saslauthd:

sudo service postfix stop
sudo service saslauthd

rm -r /var/run/saslauthd/ 
mkdir -p /var/spool/postfix/var/run/saslauthd 
ln -s /var/spool/postfix/var/run/saslauthd /var/run 
chgrp sasl /var/spool/postfix/var/run/saslauthd
adduser postfix sasl
Refrences

http://www.jimmy.co.at/weblog/2005/12/05/postfix-and-sasl-debian/

http://www.postfix.org/SASL_README.htm

https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-postfix-on-ubuntu-16-04