Virtual Users And Domains With Postfix, Courier, MySQL And SquirrelMail (CentOS 6.2 x86_64) - Page 3

9 Configure Saslauthd

Edit /etc/sasl2/smtpd.conf. It should look like this:

vi /etc/sasl2/smtpd.conf

pwcheck_method: authdaemond
log_level: 3
mech_list: PLAIN LOGIN

Then turn off Sendmail and start Postfix, saslauthd, and courier-authlib:

chmod 755 /var/spool/authdaemon
chkconfig --levels 235 courier-authlib on
/etc/init.d/courier-authlib start

chkconfig --levels 235 sendmail off
chkconfig --levels 235 postfix on
chkconfig --levels 235 saslauthd on
/etc/init.d/sendmail stop
/etc/init.d/postfix start
/etc/init.d/saslauthd start


10 Configure Courier

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

vi /etc/authlib/authdaemonrc

#authmodulelist="authuserdb authpam authpgsql authldap authmysql authcustom authpipe"

Then edit /etc/authlib/authmysqlrc. It should look exactly like this (again, make sure to fill in the correct database details):

cp /etc/authlib/authmysqlrc /etc/authlib/authmysqlrc_orig
cat /dev/null > /etc/authlib/authmysqlrc
vi /etc/authlib/authmysqlrc

MYSQL_SERVER localhost
MYSQL_PASSWORD mail_admin_password
MYSQL_HOME_FIELD "/home/vmail"

Then restart Courier:

chkconfig --levels 235 courier-imap on
/etc/init.d/courier-authlib restart
/etc/init.d/courier-imap restart

When courier-imap is started for the first time, it automatically creates the certificate files /usr/lib/courier-imap/share/imapd.pem and /usr/lib/courier-imap/share/pop3d.pem from the /usr/lib/courier-imap/etc/imapd.cnf and /usr/lib/courier-imap/etc/pop3d.cnf files. Because the .cnf files contain the line CN=localhost, but our server is named, the certificates might cause problems when you use TLS connections. To solve this, we delete both certificates...

cd /usr/lib/courier-imap/share
rm -f imapd.pem
rm -f pop3d.pem

... and replace the CN=localhost lines in /usr/lib/courier-imap/etc/imapd.cnf and /usr/lib/courier-imap/etc/pop3d.cnf with

vi /usr/lib/courier-imap/etc/imapd.cnf


vi /usr/lib/courier-imap/etc/pop3d.cnf


Then we recreate both certificates...


... and restart courier-authlib and courier-imap:

/etc/init.d/courier-authlib restart
/etc/init.d/courier-imap 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 share]# telnet localhost pop3
Trying ::1...
Connected to localhost.
Escape character is '^]'.
+OK Hello there.
<-- quit
+OK Better luck next time.
Connection closed by foreign host.
[root@server1 share]#


11 Modify /etc/aliases

Now we should open /etc/aliases. Make sure that postmaster points to root and root to your own username or your email address, e.g. like this:

vi /etc/aliases

postmaster: root
root: postmaster@yourdomain.tld

or like this (if administrator is your own username):

postmaster: root
root: administrator

Whenever you modify /etc/aliases, you must run


afterwards and restart Postfix:

/etc/init.d/postfix restart

Share this page:

14 Comment(s)

Add comment


From: Habeeb at: 2012-02-01 23:21:14

Dear Admin,

 I am getting this below error while building the rpm for postfix, so please advice what i should now??? Still i am in the first page.


[root@example SPECS]# rpmbuild -ba postfix.spec
error: Name field must be present in package: (main package)
error: Version field must be present in package: (main package)
error: Release field must be present in package: (main package)
error: Summary field must be present in package: (main package)
error: License field must be present in package: (main package)
[root@example SPECS]#

From: Arash S. at: 2012-03-20 12:45:46

Hi there,

the download address for epel has been changed. it is: ""



From: Anonymous at: 2013-03-21 10:28:48

 "epel-release-6-5.noarch.rpm" is not there / anymore. 

Try this instead: 



From: Hillary John at: 2012-05-22 20:53:08


From: Skaroth at: 2012-07-21 14:08:45

Thank you for this great tutorial. Perfectly written!

From: Alberto at: 2012-09-27 14:40:01


 Thanks for this great HowTo.

 I´m trying to adapt this installation to use with  postfixadmin, but i´m having a lot of problems, could anybody let a link to a HowTo or something like that?


Thanks a lot.

From: dusko at: 2012-03-01 16:21:23


Thank you for a really useful guide!

I'm wondering what changes would be needed to use ViMbAdmin to administrate mail server created in this guide?

On I've found general instructions for the integration.

I suppose in ViMbAdmin integration guide that mail store is Maildir or mbox, not the mysql database.

Finally, is ISPConfig3 better solution then  ViMbAdmin?

From: Silent at: 2012-03-17 00:17:23

You forgot to install the cyrus-sasl-plain Package in your Guide.

it doesn't show till you actually try postfix in step 15, where it will continuously fail because it cannot find any SASL Authentication mechanisms.

From: Sandeep Rohilla at: 2012-02-02 12:12:05

Hi, Document is good, but i am not able to send and receive mails one more thing when i try to login with webmail, its show ERROR: Connection dropped by IMAP server.

and i am not able to connect with mail client also it - shows not able to connect and showing password or userid incorrect  

Please help me 

From: at: 2012-08-28 10:01:28

@ 3 above comments,

 To "enable" a mailbox, first send a mail to it. it will create the folders and after you will be able to connect to imap.

From: Sandeep Rohilla at: 2013-03-30 11:28:19


I resolved it by changing the permissions and username of mysql in configuration file. But i just wanted to know 2 things. I am trying to make a mailserver replica, so that if one is down it automatically switch to 2nd one. what package i will use to do so. one more thing if i want to make a backup copy of my server running on different IP  and diffrent FQDN name. Can I use the backup server by changing the IP and FQDN name? Do i need to regenerate all the certificates?

From: Anonymous at: 2013-04-22 03:41:56

Hi Sandeep..

Im also facing same problem. "Connection dropped by IMAP server". But im not able to understand what exactly u have mentioned. Resolved by "changing permissions and username of mysql"

Can u make it clear..




From: at: 2012-03-16 13:39:28

i doesn't crate the folders in /home/vmail

ERROR: ERROR: Could not complete request.
Reason Given: Unable to open this mailbox.


ERROR: ERROR: Connection dropped by IMAP server.

From: mac at: 2012-06-02 11:23:38


   Your tutorial is good, But when i am try to login through webmail  its shows error as ERROR: Connection dropped by IMAP server. and when checked the log file server imapd: chdir No such file or directory and in next line server imapd: No such file or directory but when i tried the authtest -s imap 12345 authenticatied sucessfullly.

Please help me...