Mentis Homepage Thought Hardware Software Design About Search Move up one level
Software Tutorials

Courier Setup guide on RedHat 7.0


Courier is a mail server, this is a tutorial on how to install it in Red Hat Linux.

Remember that this is just how I choose to do my install and of course it could all be wrong. As always proceed at your own risk! :)

Install of Courier:

First, DO NOT BE SUPER USER for this part!!

Well first downloaded the newest version and un-tarred my version was 0.31.0:

[trevor@localhost tmp]$ tar -zxvf courier-0.31.0.tar.gz
[trevor@localhost tmp]$ cd /courier-0.31.0

Once this is all done I have a nice new directory called "courier-0.31.0". Now I ran the next step which was a ./configure.

[trevor@localhost courier-0.31.0]$ ./configure

And to my surprise I got an error.... Me of all people getting an error in linux! Zessh what is the world coming too! So after I cooled down I went on the look out for my missing development RPMs, as far as I knew I was looking for GDBM, this is what I ended up installing (off my Red Hat CD) to get going:

compat-egcs-6.2- compat-egcs-c++-6.2-
libstdc++-2.96-54.i386.rpm compat-egcs-objc-6.2-
libstdc++-devel-2.96-54.i386.rpm compat-libstdc++-6.2-
gdbm-devel-1.8.0-5.i386.rpm compat-egcs-g77-6.2-
kgcc-1.1.2-40.i386.rpm compat-glibc-6.2-

Now I am not really too sure if all of these files were needed, I will have to look into that later, my main concern is getting the damn server up! After a quick check to see if the ./configure worked I found myself watching endless pages of code (nerdscreens), I succeeded!! The command prompt awaited my next entry. The Install guide says "reward yourself by typing make. If make completes successfully, run make check."

[trevor@localhost courier-0.31.0]$ make
[trevor@localhost courier-0.31.0]$ make check

Well make worked!!! Let see about make check now, another set of nerdscreens (Linux code screens...) and make check succeeded also. Feeling pretty good at this point I decide to take a break for some noddles. After a nice bowl of noodles I see my next step is to su myself:

[trevor@localhost courier-0.31.0]$ su
[root@localhost courier-0.31.0]# 

Once you are superuser run make install.

[root@localhost courier-0.31.0]# make install

The nerdscreens come a flying again! Rule of thumb, if it takes a long time then its good. make install goes with no errors too! I am pretty much beside myself now, as I have only run into a few problems up to this point.

I now need to run make install-configure:

[root@localhost courier-0.31.0]# make install-configure

Post Installation

Now since we have the install going I would like to add the ability to search the MAN pages for courier. This can be done intwo ways, one is by adding an entry to the man.config file, the other by copying the files to a man directory already specified. I decided just to edit the darn file. Mine is located in the /etc directory (where yours should be too!). Here is the list of MANPATHs that I have in my own man.config

#Begin of CUT

MANPATH /usr/share/man
MANPATH /usr/man
MANPATH /usr/X11R6/man
MANPATH /usr/lib/perl5/man
MANPATH /usr/kerberos/man
MANPATH /usr/local/man
MANPATH /usr/lib/courier/man [added to get to Courier MAN pages]


Now time to copy all the Pam files to the correct spot (see PAM configuration in Install guide) done as follows:

[root@localhost courier-0.31.0]# cp /usr/lib/courier/etc/pop3d.authpam /etc/pam.d/pop3
[root@localhost courier-0.31.0]# cp /usr/lib/courier/etc/imapd.authpam /etc/pam.d/imap
[root@localhost courier-0.31.0]# cp /usr/lib/courier/etc/webmail.authpam /etc/pam.d/webmail
[root@localhost courier-0.31.0]# cp /usr/lib/courier/etc/esmtp.authpam /etc/pam.d/esmtp

This allows POP3, IMAP, webmail and authenticated SMTP. Once this is all setup and done you are ready to start up courier!! Here we go:

[root@localhost courier-0.31.0]# /usr/lib/courier/sbin/courier start
[root@localhost courier-0.31.0]# /usr/lib/courier/sbin/pop3d start
[root@localhost courier-0.31.0]# /usr/lib/courier/sbin/imapd start
[root@localhost courier-0.31.0]# /usr/lib/courier/sbin/esmtpd start

I now have all the system up! But I still have sendmail running! So to stop the sendmail process we will do:

[root@localhost courier-0.31.0]# /etc/rc.d/init.d/sendmail stop

Ok, where are we, Courier is installed, pam.d files copied, courier running, and the POP3, IMAP, and SMTP services are up as well. Well since we are still technically setting up the system here I think it best to continue on that route. First duty is to change the system Postmaster alias to point to a user. Since Courier does not deliver any mail to root, you must point it to someone else. This step is pretty easy actually, edit the file /usr/lib/courier/etc/aliases/system. The file will look somewhat like this below:

#Begin file cut

root: postmaster
mailer-daemon: postmaster
MAILER-DAEMON: postmaster
uucp: postmaster


All you need to do is edit the postmaster: line, append to it the username of the new email guru, for me it was simple postmaster: trevor. Once you have done this you must run the makealiases command to update the alias database:

[root@localhost courier-0.31.0]# /usr/lib/courier/sbin/makealiases

Ok, well lets get on with the business eh! Time to start making a Maildir. Courier doesn't deliver mail like sendmail, it instead uses a 'Maildir', that is as far as I can explain the Maildir without making myself look silly. Switch to a regular user (a user you want to setup for email, not root) and run this command:

[root@localhost courier-0.31.0]# su trevor
[trevor@localhost courier-0.31.0]$ /usr/lib/courier/bin/maildirmake $HOME/Maildir
[trevor@localhost courier-0.31.0]$ exit

Since we are using the defaults here make sure to do it exactly like shown, $HOME = the current user's home directory, Maildir is the location that courier will drop the mail into. Note that it is Maildir, not maildir.

Now to send a test message so we can see if it is working send a test message to user trevor (Maildir has been made for):

[root@localhost courier-0.31.0]# echo "To: trevor" | /usr/lib/courier/bin/sendmail

This will send a message (an empty one) to the user trevor. Setup a POP account on another machine and see if it got sent!

If it did, congrats! If not sorry, I unfotuneatly do not have much else for you if you did not receive the message. Back to the people who made it, we still have a few things left to set up. First let's edit the SMTP access file so that you can send from other locations. To do this we need to edit the file /usr/lib/courier/etc/smtpaccess/default (default is the actual filename). Here is the way mine looks after editing it:


# localhost, this should always be there allow,RELAYCLIENT

# relay from my internal network which is one a 192.168.0 scope
192.168.0 allow,RELAYCLIENT

# for the list of ip's where I could be that need to authorized as follows
22.212 allow,RELAYCLIENT
22.93 allow,RELAYCLIENT
23.41 allow,RELAYCLIENT


There now that this is setup I will be able to send email from all over the place, but say I go on vacation and want to send email from some foreign IP, short of adding it to the table, I would just want to use authorized user. To do that we need to edit /usr/lib/courier/etc/esmtpd. There are a couple changes that need to be done on this, the first is that we need to set this file up so that it starts automatically when the system boots up, the other as mentioned a second ago is to allow authorized users. Majority of the editing takes place on or close to the very bottom. Take a look at the last few lines, it really starts on line 269 of the file (my comments in orange):


# To enable authenticated SMTP relaying, uncomment AUTHMODULES, <-- Line 269 ---
# and set ESMTPAUTH to ESMTP authentication mechanisms we support. Currently
# LOGIN and CRAM-MD5 are available:
AUTHMODULES="authcustom authcram authuserdb authpam" [I uncommented this line]
ESMTPAUTH="LOGIN CRAM-MD5" [I uncommented this line]

# To enable SASL PLAIN authentication when using TLS, uncomment the following.
# To enable SASL PLAIN with or without TLS, just add PLAIN to ESMTPAUTH,
# above:

# ESMTPDSTART is not referenced anywhere in the standard Courier programs
# or scripts. Rather, this is a convenient flag to be read by your system
# startup script in /etc/rc.d, like this
# prefix=/usr/lib/courier
# exec_prefix=/usr/lib/courier
# . ${sysconfdir}/esmtpd
# case x$ESMTPDSTART in
# x[yY]*)
# /usr/lib/courier/sbin/esmtpd start
# ;;
# esac
# The default setting is going to be NO, until Courier is shipped by default
# with enough platforms so that people get annoyed with having to flip it to
# YES every time.

ESMTPDSTART=YES [Default is to NO, but i would like to start this on boot!!]


There ya go! I now have it allowing me to be anywhere, and to start automatically.

Now since we want the other programs starting on boot we will have to edit the last line of them all, I edited /usr/lib/courier/etc/imapd and /usr/lib/courier/etc/pop3d. both simply had to have the last line changed to YES.

System Startup

Ok, so far we have told the child processes to start, but we haven't started the parent program, lets take a look. We need to make the init script, this is taken right from the courier install file. Grab mine, called 'courier' and save it in your /etc/rc.d/init.d folder. Don't forget to make it executable!

[root@localhost courier-0.31.0]# chmod +x /etc/rc.d/init.d/courier

Heck we aint done yet!!

Now we need to get rid of SENDMAIL for good, damn thing... What we need to do here is remove any symlinks to SENDMAIL in the run level directories (/etc/rc.d/rc0.d-rc6.d) and replace those with new symlinks to the Courier startup file (/etc/rc.d/init.d/courier). Most of the SENDMAIL files will be called K30sendmail or S80sendmail (k for kill, s for start). Here is the list of symlinks I had to delete and replace. First we delete:

[root@localhost rc.d]$ rm /etc/rc.d/rc0.d/K30sendmail
[root@localhost rc.d]# rm /etc/rc.d/rc1.d/K30sendmail
[root@localhost rc.d]# rm /etc/rc.d/rc2.d/S80sendmail
[root@localhost rc.d]# rm /etc/rc.d/rc3.d/S80sendmail
[root@localhost rc.d]# rm /etc/rc.d/rc4.d/S80sendmail
[root@localhost rc.d]# rm /etc/rc.d/rc5.d/S80sendmail
[root@localhost rc.d]# rm /etc/rc.d/rc6.d/K30sendmail

Once deleted I need to replace them with the courier links like so:

[root@localhost rc.d]$ ln /etc/rc.d/init.d/courier /etc/rc.d/rc0.d/K30courier
[root@localhost rc.d]# ln /etc/rc.d/init.d/courier /etc/rc.d/rc1.d/K30courier
[root@localhost rc.d]# ln /etc/rc.d/init.d/courier /etc/rc.d/rc2.d/S80courier
[root@localhost rc.d]# ln /etc/rc.d/init.d/courier /etc/rc.d/rc3.d/S80courier
[root@localhost rc.d]# ln /etc/rc.d/init.d/courier /etc/rc.d/rc4.d/S80courier
[root@localhost rc.d]# ln /etc/rc.d/init.d/courier /etc/rc.d/rc5.d/S80courier
[root@localhost rc.d]# ln /etc/rc.d/init.d/courier /etc/rc.d/rc6.d/K30courier


Since I am going to be using IMAP I would really like to turn on the server side filtering aspects of it, to do this I need to enable a few more lines in the courierd file. Lets edit /usr/lib/courier/etc/courierd. Here is a snapshot of my DEFAULTDELIVERY section on line 50.


# Specify default delivery instructions by setting DEFAULTDELIVERY
# One of the following definitions of DEFAULTDELIVERY should be
# uncommented.
# Default deliveries to $HOME/Maildir
# DEFAULTDELIVERY=./Maildir [I think I commented this line]
# Alternatively, use procmail to deliver mail to local mailboxes.
# DEFAULTDELIVERY="| /usr/lib/courier/bin/preline /usr/bin/procmail"
# Here's how to have maildrop handle local deliveries.
DEFAULTDELIVERY="| /usr/lib/courier/bin/maildrop" [uncommented this line]
# If you want to automatically enable .forward support globally,
# use something like this:
# DEFAULTDELIVERY="|| dotforward
# ./Maildir"
# Yes, it's two lines long, with an embedded newline. Of course, you can use
# any default local mail delivery instruction in place of ./Maildir.
# DEFAULTDELIVERY=./Maildir ### commented this line


There now the filtering should be enabled. I also have to create a new file called /usr/lib/courier/etc/maildirfilterconfig, since I will be using the webmail to make my rules (seems easier). The file simply contains this:


Final Workings

Thats it!! After that a quick reboot and everything was up and running. A POP, IMAP, and SMTP server. To make life easier we are going to edit the skeleton user in Red Hat. This will make any new user that is created already have the Maildir. So lets do it! Make sure you are root and enter this command:

[root@localhost /]# /usr/lib/courier/bin/maildirmake /etc/skel/Maildir

Done. Now I created a new test user, so lets give it a shot in the mail client. Worked? Perfect!

A few other things you may want to do is to make some links, for instance kill the current mailq and poit it to /usr/lib/courier/bin/mailq. This is done by the following two steps:

[root@localhost /]# rm /usr/bin/mailq
[root@localhost /]# ln -s /usr/lib/courier/bin/mailq /usr/bin/mailq

Done and done. Now you can check the mailq from anywhere by doing a simple mailq command.