Blue Flower

Monday, 06 July 2015 01:29

Installing Courier-Imap

Written by
Rate this item
(0 votes)

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 http://www.courier-mta.org/imap/


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:

IPV6
AUTH_VCHKPW

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:


enable_courier-authdaemond="YES"

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
# fetch http://freebsdrocks.net/files/service-courierpassd-run
# mv service-courierpassd-run run
# chmod 755 run
# mkdir -m 755 log
# cd log
# fetch http://freebsdrocks.net/files/service-any-log-run
# mv 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 section:


authmodulelist="authvchkpw"

Now to setup the courier-authdaemond service:


# cd /var/qmail/supervise
# mkdir -m 1755 courier-authdaemond
# cd courier-authdaemond
# fetch http://freebsdrocks.net/files/courier-authdaemond-run
# mv courier-authdaemond-run run
# chmod 755 run
# mkdir -m 755 log
# cd log
# fetch http://freebsdrocks.net/files/service-any-log-run
# mv 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 deleted from /etc/rc.conf


Enable_courier-imap-imapd="YES"
Enable_courier-imap-imapd-ssl="YES"

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
# fetch http://freebsdrocks.net/files/courier-imap-run
# mv courier-imap-run run
# chmod 755 run
# mkdir -m 755 log
# cd log
# fetch http://freebsdrocks.net/files/service-any-log-run
# mv 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/

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
# fetch http://freebsdrocks.net/files/courier-imap-ssl-run
# mv courier-imap-ssl-run run
# chmod 755 run
# mkdir -m 755 log
# cd log
# fetch http://freebsdrocks.net/files/service-any-log-run
# mv 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. It works quite well and I have been using it for a month now. Here it is:


# cd /var/qmail/bin
# fetch http://freebsdrocks.net/files/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!

Read 2226 times Last modified on Monday, 06 July 2015 02:08

Leave a comment

Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.