Installing Courier-Imap

Courier-IMAP is a server that provides IMAP access to Maildir mailboxes. This IMAP server does NOT handle traditional mailbox files (/var/spool/mail, and derivatives), it was written for the specific purpose of providing IMAP access to Maildirs. For more information, please visit

Lets start with installing the port and configuring the options for it:

# echo "WITHOUT_X11=yes" >> /etc/make.conf
# echo "NO_X=yes" >> /etc/make.conf
# cd /usr/ports/lang/expect
# make install clean
# cd /usr/ports/mail/courier-imap
# make install clean

When you run make install clean on courier-imapd, be sure to make sure the following boxes are checked:


Once that is done, We will want to install courierpassd:

# cd /usr/ports/security/courierpassd
# make install clean

Now we will want to delete the startup file in the /usr/local/etc/rc.d folder:

# rm /usr/local/etc/rc.d/courier-authdaemond

and make sure that the following line is NOT in /etc/rc.conf:


Next we need to set up the daemontools directory structure for the courierpasswd service. I use /var/qmail/supervise as the physical location for my service directories, you can use whatever you like except that it cannot be /service itself. The examples below will assume you are using /var/service like I did- if you are using something different, adjust the paths where appropriate.

# cd /var/qmail/supervise
# mkdir -m 1755 courier-passwd
# cd courier-passwd
# cp /downloads/qmailrocks/service-courierpassd-run run
# chmod 755 run
# mkdir -m 755 log
# cd log
# cp /downloads/qmailrocks/service-any-log-run run
# chmod 755 run

The last step, of course, is to start the service running:

# ln -s /var/qmail/supervise/courier-passwd /service/courier-passwd

You can verify the service is running by typing: 

# svstat /service/courier-passwd/ /service/courier-passwd/log/

Now we want to setup a few files: 

# cd /usr/local/etc/courier-imap
# cp imapd.cnf.dist imapd.cnf
# cp imapd-ssl.dist imapd-ssl

Now we need to make the imap cert:

# /usr/local/share/courier-imap/mkimapdcert

Now edit the following file:

# vi /usr/local/etc/authlib/authdaemonrc

And change the following line inside authdaemonrc to look like so:


Now to setup the courier-authdaemond service: 

# cd /var/qmail/supervise
# mkdir -m 1755 courier-authdaemond
# cd courier-authdaemond
# cp /downloads/qmailrocks/courier-authdaemond-run run
# chmod 755 run
# mkdir -m 755 log
# cd log
# cp /downloads/qmailrocks/service-any-log-run run
# chmod 755 run

and finally link authdaemond to /service:

# ln -s /var/qmail/supervise/courier-authdaemond /service/courier-authdaemond

And now to check to see if courier-authdaemond is running:

# svstat /service/courier-authdaemond/ /service/courier-authdaemond/log/

 Now, before we start to work on getting courier running via daemontools rather than using the scripts, we are going to want to delete the scripts in /usr/local/etc/rc.d:

# rm /usr/local/etc/rc.d/courier-imap-imapd
# rm /usr/local/etc/rc.d/courier-imap-imapd-ssl

Make sure the following two lines are not in /etc/rc.conf 


This last bit is VERY important, we dont want courier-imap trying to start twice with the next reboot, be sure and take the command to start the service OUT of /etc/rc.conf.

Now we want to make service directories for courier-imap just like you did for courierpassd

# cd /var/qmail/supervise
# mkdir -m 1755 courier-imap
# cd courier-imap
# cp /downloads/qmailrocks/courier-imap-run run
# chmod 755 run
# mkdir -m 755 log
# cd log
# cp /downloads/qmailrocks/service-any-log-run run
# chmod 755 run

Now we link the courier-imap to service:

# ln -s /var/qmail/supervise/courier-imap /service/courier-imap

Now we need to check and make sure courier-imap is running:

# svstat /service/courier-imap/ /service/courier-imap/log/

Optional Step: Enabling Courier-Imap SSL

If you want to run an imap ssl service you can, but you need to set that up separately from the stock imap service.  I use both, I set up the plain imap service bound to the localhost address only, that way only my web mail (and any local service) can access it.  the ssl service is for all your public interfaces.

# cd /var/qmail/supervise
# mkdir -m 1755 courier-imap-ssl
# cd courier-imap-ssl
# cp /downloads/qmailrocks/courier-imap-ssl-run run
# chmod 755 run
# mkdir -m 755 log
# cd log
# cp /downloads/qmailrocks/service-any-log-run run
# chmod 755 run

Now link your imap-ssl service so daemontools will start it.

# ln -s /var/qmail/supervise/courier-imap-ssl /service/courier-imap-ssl

I have modified the existing qmailctl and called it imapctl. This script will control the imap files. Here it is:

# cd /var/qmail/bin
# cp /downloads/qmailrocks/imapctl imapctl
# chmod 755 imapctl

If you run imapctl stat, you should get a output for imap related services. Very cool, huh? 

Once the courier daemons are started, we are all done here! WOOT!

Installing Squirrelmail