Howto - Configuring Postfix + SASL + MySQL for SMTP Auth

Version 1.0 / 22-Sep-2007
Bill Pitz

Managed IT and Network Engineering: North Bay Logistics, LLC


DISCLAIMER: What follows is the result of my personal findings. What worked for me may not work for you. This document describes setting up MySQL authentication using cleartext passwords. Do not use unless you have a secure channel between the Postfix/SASL server and the MySQL server. I am sharing this information in the hope that it will help others, but in no way will or do I accept any responsibility for whatever may occur as a result of your using this document. You have been warned.

Objectives

  • A Postfix SMTP server which will perform SMTP AUTH (via AUTH LOGIN commands) against a MySQL database.
  • The Cyrus SASL package should use its own connection to the database rather than relying on PAM.

    I thought this would be a simple undertaking, but it turned out not to be. The web is polluted with dozens of HOWTO guides that all go about accomplishing this goal in different ways. Unfortunately, none of them matched what I wanted to do -- perform SMTP AUTH against a MySQL database in the simplest fashion possible. I quickly discovered that Cyrus-SASL is sorely lacking documentation and is extremely difficult to understand and troubleshoot.

    After a great deal of searching, trying, and failing, I finally discovered that it is not necessary to run saslauthd in order to perform the SASL authentication against MySQL. What follows is the bare minimum that I needed to perform in order to get Postfix+SASL+MySQL SMTP AUTH working. Comments welcome, but as always, YMMV. Good luck.

    I. What you need:

    II. Compile Cyrus-SASL

    III. Configure Cyrus-SASL for Postfix

    IV. Configure Postfix for Cyrus-SASL

    V. Debugging

    Unfortunately, the debugging for this option is not particularly great. Your maillog (/var/log/maillog or /var/log/mail) is the best place to look for information. Postfix will drop some of the SASL authentication output here, particularly upon failure. Some information is also logged to /var/log/messages. This worked for me, after hours of searching and trying various configurations. Like with all HOWTOs, YMMV.