Originally Published: Monday, 20 August 2001 Author: Henry Chen
Published to: enhance_articles_sysadmin/Sysadmin Page: 4/4 - [Printable]

Install and Test Qmail with POP, IMAP and WebMail

Kill Sendmail? Are you kidding me? Well, no. In this first run original article Henry Chen provides us with free detailed step-by-step instructions for installing Qmail with Redhat 7.1, an alternative open source solution to your mail management needs.

  << Page 4 of 4  

Adding New Users

Setting up /etc/skel

This Maildir directory structure, especially with all the IMAP folders, gets complicated.  So, as the root user, I recommend the following: 

mkdir /etc/skel/Maildir
mkdir /etc/skel/Maildir/cur
mkdir /etc/skel/Maildir/new
mkdir /etc/skel/Maildir/tmp
mkdir /etc/skel/Maildir/.Trash
mkdir /etc/skel/Maildir/.Trash/cur
mkdir /etc/skel/Maildir/.Trash/new
mkdir /etc/skel/Maildir/.Trash/tmp
mkdir /etc/skel/Maildir/.Drafts
mkdir /etc/skel/Maildir/.Drafts/cur
mkdir /etc/skel/Maildir/.Drafts/new
mkdir /etc/skel/Maildir/.Drafts/tmp
mkdir /etc/skel/Maildir/.Sent\ Items
mkdir /etc/skel/Maildir/.Sent\ Items/cur
mkdir /etc/skel/Maildir/.Sent\ Items/new
mkdir /etc/skel/Maildir/.Sent\ Items/tmp

Now, whenever we create a new user with the useradd command, the new user will get a set of IMAP folders that mimics Exchange 2000.  The Trash folder will also catch all the e-mails that the user expunges.  The .Sent\ Items directory mimics Exchange 2000's Sent Items folder and it will catch the sent mails from IMP. 

Setting up quota

It is also useful to setup quotas for the /home directory.  To do this, you have to edit the /etc/fstab file.  I replace this line:

LABEL=/home  /home  ext2  defaults  1 2 

With this line:

LABEL=/home  /home  ext2  defaults,usrquota  1 2 

Now, you need to reboot the server for this to take hold.  It is a good time to reboot the server anyway, to test whether all the boot up scripts for Qmail and Courier IMAP will work properly.

After the server reboots, you should see that the Qmail stuff is running with supervise, a bunch of multilog processes, and some Courier IMAP related processes.  To complete the quota setup, do this:

su
touch /home/aquota.user
/usr/sbin/quotacheck /home 

quotacheck will report some errors because the aquota.user file that you just created is garbage and quotacheck just made it right.  I also created this script to make life simpler vi /root/newuseradd

#!/usr/bin/perl
#
# Wrapper for useradd and setquota
# Usage: newuseradd [username] [password] "[comment]"

use POSIX;

if ($ARGV[0] eq '' || $ARGV[1] eq '' || $ARGV[2] eq '') {
    print "Usage: sxuseradd [username] [password] \"[comment]\"\n";
    exit; }

$username = $ARGV[0];
$comment = $ARGV[2];

# Encrypt password
srand($$^time&$ENV{RANDOM});
$salt = seedchar().seedchar();
$password = crypt($ARGV[1],$salt);

system "/usr/sbin/useradd -g client -c \"$comment\" -p $password $username";
system "/usr/sbin/setquota /home 0 10000 0 0 $username";

exit;

sub seedchar {
    ('a'..'z','A'..'Z','0'..'9','.','/')[rand(64)];
} 

This assumes that you want to give new users a 10MB disk quota for e-mail.  I also used crypt instead of the PAM thing so this does not give you as good an encrypted password as Red Hat's default useradd.  Then, I added the following command aliases to root's .bashrc file: 

echo "alias useradd=/root/newuseradd" >> /root/.bashrc

And don't forget to add the client group and make the new script executable: 

/usr/sbin/groupadd client
chmod 755 /root/newuseradd 

So, now, every time you do an useradd, you will also take care of the disk quota. 

Testing

Setup a few new users to make sure that they all have the correct Maildir directory structure.  Check with the IMAP client to make sure that (1) you can login and (2) the correct IMAP folders show up.  If you don't care for the web interface for IMAP, you can stop now.

Install IMP

I thought about getting the tarball for horde and IMP but I am so tired by this point that I gave the RPM's a try and they worked!  All the RPMs do is that they add some directories and files to the /var/www directory structure.  As horde/ IMP is designed as an add on module to the web server, the RPM's for Red Hat 7.0 worked just fine.

MySQL

Before you can begin installing horde and IMP RPMs, you must first install the mysql and php-mysql RPMs and start the mysql and apache server.  To install RPMs, I did this (as root):

rpm -ivh package_name

To start mysql and apache (and at boot time), I did these:

/etc/init.d/mysqld start
/etc/init.d/httpd start
cd /etc/rc3.d
mv K12mysqld S12mysqld
mv K15httpd S15httpd

We need MySQL because we want to enable the preference and address book functions in IMP.  Remember to secure MySQL by doing this:

mysqladmin -u root password new_password

Horde/IMP

Now to install horde and IMP (note the sequence, and you are still root):

rpm -ivh horde-1.2.6-1rh7.noarch.rpm 
rpm -ivh horde-mysql-1.2.6-1rh7.noarch.rpm 
rpm -ivh imp-2.2.6-1rh7.noarch.rpm

The horde/IMP installation packages are so well made that they give you almost all the instructions that you need to complete the rest of the installation.  I followed the instructions and did these:

cd /var/www/html/horde
sh install.sh

Then, I went to my browser and opened up http://yourhostname/horde/setup.php3  This created the /var/www/html/horde/imp/config/defaults.php3 file.  I am noting the following changes from default:

$default->localhost  = 'IP address of your server';
$default->server      = 'IP address of your server';
$default->from_server = 'your domain name';

It is important to use the IP address, instead of the hostname.  Otherwise, your virtual domain clients will not be able to use IMP if they do not specify the exactly correct hostname of your e-mail server.

$default->sent_mail = 'Sent Items';
$default->postponed = 'Drafts';

Note that these are the IMAP folders we created earlier.  And they mimic Exchange 2000.

/* Cyrus Configuration */
$default->personal_folders = 'INBOX.'

Watch out for this one on the web configuration interface.  If you don't do this, IMP will not be able to see the other folders (under Inbox).

/* Database Configuration */
$default->use_db          = true;
$default->database_driver = 'mysql';

This enables MySQL for IMP.  Once the web configuration is complete, do this on console (you are still root):

sh secure.sh
mysql < /var/www/html/horde/scripts/database/mysql_create.sql
/var/www/html/horde/scripts/database/dbpasswd.sh

For the last two command lines, MySQL will prompt you for a password.  You should use the new_ password that you setup earlier to secure MySQL.  The first command creates the proper MySQL database and the second secures the horde database.  Also, if you don't run secure.sh and secure the horde database, IMP will refuse to start.  

Testing

To play with IMP, goto http://yourhostname/horde/imp/  To make life simpler, I created a new /var/www/html/index.html file with these:

<HTML>
<meta http-equiv="refresh" content="0; URL=/horde/imp/">
</HTML>

So now, http://yourhostname/ will end up in the IMP login screen.

Finish

Congratulations!!!  You have just completed setup your new e-mail server with SMTP (with relay from authenticated users), POP, IMAP and web interface to the IMAP server.

Credit

I sourced a lot of people's material.  I am trying to list all of them here.  If I miss any, let me know and I will add them here:

Contracting

If all these is too much for you and you just want this to be done and someone to take care of it, you should consider contracting SurfXpress (and I will be involved) for a dedicated server solution and negotiate a server management contract with us.  We can provide you with a full e-mail hosting solution package.

Licensing

I have not given this much thought.  I guess this is covered by the OpenContent License, version 1.0. See http://www.opencontent.org/opl.shtml for the full license. Basically, you can copy, redistribute, or modify this document provided that modified versions, if redistributed, are also covered by the OpenContent License.

No Warranty

A lot of legal stuff should go here.  Basically, it will say that this document is provided as is and there is no warranty of any kind...  See the OpenContent License mentioned above.

Contribution

Please send corrections, suggestions, complaints, fix any typo, grammatical errors, etc.  to henry@sxpress.com.

Or, you can contribute to my personal sanity by buying some stuff for me from Amazon.





  << Page 4 of 4