This is a short write up for an easy way to install Courier-IMAP on a machine running Mac OS X client (and probably just the Darwin core as well)


I wanted to have my own IMAP-server both for archival purposes (on my own machine I have practilcally unlimited space to save e-mail) as well as a mean to collect mail I receive on other accounts into one unified storage. Furthermore I want a better way to handle mail than common e-mail clients like Apple Mail, Thunderbird or Eudora offers - currently I am looking into Zoƫ (Google you e-mail) and Mulberry (the superior, with a good margin, IMAP-client)

I will do this step by step and update this document as I progress:

  1. Install Courier-IMAP
  2. Arrange a simple ugly setup to fetch and filter mail
  3. Make Courier use (x)inetd
  4. Setup a stable mail fetching function, probably with fetchmail or something similar
  5. Install server side filtering (sieve)
  6. Install server side anti-spam means
  7. Setup an LDAP-server that cooperates with the Address Book in Mac OS X, the server side anti-spam functionality and the e-mail clients built in address books.
  8. Enable SSL-support.


Install and setup Courier-IMAP

  1. Install DarwinPorts
  2. Note how you got a new Startup Item in /Library/StartupItems
  3. Use DarwinPorts to install courier
    port install courier-imap
  4. Now you have a lot of courier-stuff in your /opt/local. The following are of interest:
    in /opt/local/bin/
    in /opt/local/etc/courier-imap/
    in /opt/local/libexec/

Before we begin to dissect these we first have to understand something else:

DarwinPorts StartupItem

The DarwinPorts StartupItem basically runs all items in (typically) /opt/local/etc/rc.d/ with the verb start. With that in mind we can look into the start up procedure of Courier-IMAP and its startup scripts:


When you install Courier-IMAP the following script are stored in /opt/local/etc/rc.d/ and are therefore executed(with the verb start) when the computer boots:

These scripts are quite similar, they source /opt/local/etc/courier-imap/imapd (and imapd-ssl) and then execute /opt/local/libexec/imapd.rc start (imapd-ssl.rc). Now that we know this we can go back to the files of interest mentioned above. We begin with last of the two files the start scripts uses, the run command files:


These run command files set up some environment variables and then launches the executable with a few switches.

imapd/imapd-ssl in /opt/local/etc/courier-imap/

These are the setting files for Courier-IMAP. They are fairly well documented/commented. I made a few changes:


I changed its value from 0 to This way you can have a secure setup without having to mess with the SSL-setup1 at the moment since you only allow connections from localhost which forces clients to tunnel their traffic to the machine where Courier-IMAP is running, e.g., by SSH. If the tunnel is setup as it should then this method is perfectly safe.


I commented this setting to make the server behave more like regular MUA:s, i.e., not deleting messages in the trash automatically.

Note that these configration files have the same names as the executables in /opt/local/bin/.

imapd in /opt/local/bin/

This is the actual IMAP-server executable. You can, but I advise against it, start this directly from the command line. It has an extensive man-page.


You have to run this for each user before they can log in. I have only tried to log in with Mozilla Thunderbird without first running maildirmake for a certain user and at least Thunderbird gives an error message indicating, incorrectly, that your password is erroneous if you don't do this. Simply cd to each user's home directory and run maildirmake Maildir and it will create a directory called Maildir with three sudirectories, cur, new and tmp.

You can give another name as argument to maildirmake but then, in my experience, you can not login. It seems as Courier-IMAP has hard coded the name of the mail directory because I can not find any setting for it either. If you know anything about this, please let me know.

Start the server [an error occurred while processing this directive]

If you reboot the server will start automatically but easier is just to runt the startup script in /opt/local/etc/rc.d/. Since we , for the moment, re happy with just using the plain text imapd simply start the server from the command line:

/opt/local/etc/rc.d/ start

If you take a look with top you will notice a few new processes, e.g., imapd, courierlog, couriertcp, authdemon and maybe a few more. You can verify that the server is running with

telnet localhost 143

You should see something like this:

telnet localhost 143
Trying ::1...
telnet: connect to address ::1: Connection refused
Connected to localhost.
Escape character is '^]'.

You can also make sure that you are secure by logging into another computer and try to telnet from that computer to your IMAP-server on port 143.

Now create a new account in your MUA and set it up for your new IMAP-server and play around (try to transfer som junk mail from already existing accounts/mailboxes to your new IMAP-server, create a few folders on the server etc).

Start to deliver mail to your server (the ugly way)

This is a very simple step that you probably don't need to have documented if you have gone this but anyway...

This is how I did it: create a filter with the highest/first priority in your regular MUA. Make that filter transfer a copy (it is important that it is a copy or elsewise you might lose mail if the setup proves to be unstable or unreliable) of every received mail to some folder on your IMAP-server.


It is quite simple to setup SSL:

  1. adjust the values in /opt/local/etc/courier-imap/imapd.cnf to match your name, location etc.
  2. run /opt/local/sbin/mkimapdcert as root. It does not take any arguments. This will generate a certificate that works for IMAP and is stored in /opt/local/share/courier/imapd.pem

Note that the ssl-version won't start without this certifcate. Also note that you can run SSL and clear text versions of courier-imap in parallell.