There is a new version of this tutorial available for Ubuntu 13.10 (Saucy Salamander).

Virtual Users And Domains With Postfix, Courier And MySQL (Ubuntu 6.10 Edgy Eft) - Page 3

6 Configure Saslauthd

First run

mkdir -p /var/spool/postfix/var/run/saslauthd

Then edit /etc/default/saslauthd. Remove the # in front of START=yes and add the lines PARAMS="-m /var/spool/postfix/var/run/saslauthd -r" and PIDFILE="/var/spool/postfix/var/run/${NAME}/saslauthd.pid". The file should then look like this:

vi /etc/default/saslauthd
# This needs to be uncommented before saslauthd will be run automatically

START=yes



PARAMS="-m /var/spool/postfix/var/run/saslauthd -r"

PIDFILE="/var/spool/postfix/var/run/${NAME}/saslauthd.pid"



# You must specify the authentication mechanisms you wish to use.

# This defaults to "pam" for PAM support, but may also include

# "shadow" or "sasldb", like this:

# MECHANISMS="pam shadow"



MECHANISMS="pam"

Then create the file /etc/pam.d/smtp. It should contain only the following two lines (go sure to fill in your correct database details):

vi /etc/pam.d/smtp
auth    required   pam_mysql.so user=mail_admin passwd=mail_admin_password host=127.0.0.1 db=mail table=users usercolumn=email passwdcolumn=password crypt=1

account sufficient pam_mysql.so user=mail_admin passwd=mail_admin_password host=127.0.0.1 db=mail table=users usercolumn=email passwdcolumn=password crypt=1

Next create the file /etc/postfix/sasl/smtpd.conf. It should look like this:

vi /etc/postfix/sasl/smtpd.conf
pwcheck_method: saslauthd

mech_list: plain login

allow_plaintext: true

auxprop_plugin: mysql

sql_hostnames: 127.0.0.1

sql_user: mail_admin

sql_passwd: mail_admin_password

sql_database: mail

sql_select: select password from users where email = '%u'

Then restart Postfix and Saslauthd:

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

 

7 Configure Courier

Now we have to tell Courier that it should authenticate against our MySQL database. First, edit /etc/courier/authdaemonrc and change the value of authmodulelist so that it reads:

vi /etc/courier/authdaemonrc
[...]

authmodulelist="authmysql"

[...]

Then make a backup of /etc/courier/authmysqlrc and empty the old file:

cp /etc/courier/authmysqlrc /etc/courier/authmysqlrc_orig
cat /dev/null > /etc/courier/authmysqlrc

Then open /etc/courier/authmysqlrc and put the following lines into it:

vi /etc/courier/authmysqlrc
MYSQL_SERVER localhost

MYSQL_USERNAME mail_admin

MYSQL_PASSWORD mail_admin_password

MYSQL_PORT 0

MYSQL_DATABASE mail

MYSQL_USER_TABLE users

MYSQL_CRYPT_PWFIELD password

#MYSQL_CLEAR_PWFIELD password

MYSQL_UID_FIELD 5000

MYSQL_GID_FIELD 5000

MYSQL_LOGIN_FIELD email

MYSQL_HOME_FIELD "/home/vmail"

MYSQL_MAILDIR_FIELD CONCAT(SUBSTRING_INDEX(email,'@',-1),'/',SUBSTRING_INDEX(email,'@',1),'/')

#MYSQL_NAME_FIELD

MYSQL_QUOTA_FIELD quota

Then restart Courier:

/etc/init.d/courier-authdaemon restart
/etc/init.d/courier-imap restart
/etc/init.d/courier-imap-ssl restart
/etc/init.d/courier-pop restart
/etc/init.d/courier-pop-ssl restart

By running

telnet localhost pop3

you can see if your POP3 server is working correctly. It should give back +OK Hello there. (Type quit to get back to the Linux shell.)

root@server1:/etc/postfix# telnet localhost pop3
Trying 127.0.0.1...
Connected to localhost.localdomain.
Escape character is '^]'.
+OK Hello there.
quit
+OK Better luck next time.
Connection closed by foreign host.

 

8 Modify /etc/aliases

Now we should modify /etc/aliases and specify an alias for postmaster in it. You can specify one of your existing email addresses so that you can receive notifications to postmaster. Also, change the root line so that mails for root will be forwarded to postmaster as well:

vi /etc/aliases
# Added by installer for initial user

root:   postmaster

postmaster: [email protected]

Whenever you modify /etc/aliases, you must run

newaliases

afterwards and restart Postfix:

/etc/init.d/postfix restart
Share this page:

1 Comment(s)