Fix Postfix SASL Authentication Failure

By Jimmy Bonney | June 9, 2013

Shoot again

I discussed recently how to install a minimal LAMP stack environment on a virtual server. The installation was based on TurnKey Linux Lamp distribution, which is based on Debian. However, I noticed some time ago that when trying to send emails through sendmail, nothing was sent out.

When looking through the mail logs (located at /var/log/mail.log), the recurring error was the following:

lamp postfix/smtp[2113]: warning: SASL authentication failure: No worthy mechs found

In order to fix that, it is necessary to install libsasl. Before you do that, you might want to empty the existing mail queue in order not to receive all pending mails once everything is set up properly. To do so, go to the webadmin interface or execute a postfix -f from a console or a SSH session in order to purge the queue from all existing mails.

Back to the original problem, open a terminal on the virtual server (or connect to it through SSH) and execute the following commands to install the necessary packages:

1
2
[sudo] apt-get install libsasl2-modules
[sudo] /etc/init.d/postfix restart

From now on, it should be possible to send emails. To test it out, try the following:

1
2
3
4
5
sendmail test@example.com
FROM: youremail@yourdomain.com
SUBJECT: Test email
This is a test email
.

You should receive the test email in your mailbox in no time. You can also confirm that the mail queue is empty from the admin interface of TurnKey Linux, as illustrated below.

Postfix mail queue

Since we are configuring a test environment, we’ll just configure one more thing in order to ensure that no email are sent out inadvertently to existing users. We’ll set up Mailtrap that I presented previously as the default postfix relay host. Simply follow instructions on mailtrap’s configuration page. Edit /etc/postfix/main.cf:

1
2
3
4
5
relayhost = [mailtrap.io]:2525
smtp_sasl_auth_enable = yes
smtp_sasl_mechanism_filter = plain
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd

Create a password file at /etc/postfix/sasl_passwd:

mailtrap.io id-as-provided-by-mailtrap-1234567890

And finally, rebuild password database and restart postfix:

1
2
[sudo] postmap /etc/postfix/sasl_passwd
[sudo] /etc/init.d/postfix restart

Now, all emails will be sent out to mailtrap instead.



For the time being, comments are managed by Disqus, a third-party library. I will eventually replace it with another solution, but the timeline is unclear. Considering the amount of data being loaded, if you would like to view comments or post a comment, click on the button below. For more information about why you see this button, take a look at the following article.