Install Courier-Authlib
What is Courier-Authlib ?
The Courier Authentication Library is a generic authentication API that encapsulates the process of validating account passwords. In addition to reading the traditional account passwords from /etc/passwd, the account information can alternatively be obtained from an LDAP directory; a MySQL or a PostgreSQL database; or a GDBM or a DB file. The Courier authentication library must be installed before building any Courier packages that needs direct access to mailboxes (in other words, all packages except for courier-sox and courier-analog).
Create VMAIL directory
$cd /var
$mkdir vmail
$chown -R postfix:postfix vmail
Install Courier-Authlib and SMTP AUTH
$cd /usr/ports/security/courier-authlib
Note:
You need to make sure Ticked AUTH_MYSQL before you make install
$make install clean
This will automatically install any dependency like MYSQL.. leave it untouched until finished.
Edit authdaemonrc
$cd /usr/local/etc/authlib
$mv authdaemonrc authdaemonrc-ori
$pico authdaemonrc
## uncomment this line below and edit this line to :
authmodulelist="authmysql"
Edit authmysqlrc
$cd /usr/local/etc/authlib
$mv authmysqlrc authmysqlrc-ori
Before you edit authmysqlrc, please check your postfix UID and GID.
$id postfix
uid=125(postfix) gid=125(postfix) groups=125(postfix),6(mail)
We will need postfix UID and GID in authmysqlrc config file below
$pico authmysqlrc
## Edit and change the sql user,db and password as needed
MYSQL_SERVER localhost
MYSQL_USERNAME postfix
MYSQL_PASSWORD yourpostfixpassword
MYSQL_SOCKET /tmp/mysql.sock
MYSQL_PORT 0
MYSQL_OPT 0
MYSQL_DATABASE postfix
MYSQL_USER_TABLE mailbox
MYSQL_CRYPT_PWFIELD password
MYSQL_CLEAR_PWFIELD password
MYSQL_UID_FIELD '125'
MYSQL_GID_FIELD '125'
MYSQL_LOGIN_FIELD username
MYSQL_HOME_FIELD '/var/vmail'
MYSQL_NAME_FIELD name
MYSQL_MAILDIR_FIELD maildir
Setting SMTP AUTH
$cd /usr/local/lib/sasl2
$pico smtpd.conf
pwcheck_method: authdaemond
log_level: 3
mech_list: PLAIN LOGIN
authdaemond_path:/var/run/authdaemond/socket
Change authdaemond_path permission
$chown -R postfix:postfix /var/run/authdaemond/