Hosted By

Contact Me

Misc Links

OpenNTF BlogSphere LotusGeek CoComment Custom Button

Ads by Google

Welcome to keithstric.com!

I hope you find this site useful in some way or another. I strive to bring you all sorts of geeky information and solutions to your most frustrating of issues with the occasional rant on whatever topic, technical reviews and weblog. You'll also find many products that I've developed and make available for you to use however you like. So, grab a cup of coffee, sit down and visit for a while.

Setup Courier IMAP with XMail to use Squirrelmail

04/08/2007 11:53 AM By Keith Strickland

Summary

This document was created from a need to use Squirrelmail with an XMail backend. XMail was desired due to it's capabilities (pop3 retrieval, smtp server) and the fact that it uses Maildirs instead of a mailbox. I tried to get dbmail to work on my server without success (Many thanks to Aaron Johnson for putting up with me).


Background


Like I said above XMail is a mail server for Linux (I believe there is a version for windows also but don't quote me on that) which is very robust and offers features most other mail servers don't. It includes a POP3 Server, POP3 mail retrieval from an ISP mail account, SMTP, Multiple Domain support, SMTP Authentication and there are many plugins available for Xmail to extend it. Courier-IMAP is an IMAP Server with support for Maildirs. Seems to have a small footprint and supports many types of authentication (MySql, PAM, userdb, Shadow passwords, MD5, LDAP, Pgsql).


Requirements


Apache or some other web server
Working installation of
XMail
Working installation of
MySql (this isn't required but is how I set it up)
C++ compiler

make

GDBM/DB

perl

php4


This document does not cover the installation of Apache, XMail, MySql, the compilers, GDBM, perl or php. Please refer to the installation documents available for those products.


Downloads


Download the following:

Courier-IMAP from
http://www.inter7.com/courierimap/
Squirrelmail from
http://www.squirrelmail.org/download.php
If you are running Red Hat 8.0 there is an RPM available for Squirrelmai l installation


Doing the Installation


This should be a fairly simple process. You will want to be somewhat comfortable with the command line and basic admin skills. You will need root access for most of this procedure. During this procedure anything you see in italics is a command line command (i.e. mkdir /tm/imap)


You will want to create a working directory. You can name it anything you like but for this example we'll use /tmp/imap and copy the above downloads to this directory. Your filenames may differ if you download a different version of any of these files.


mkdir /tmp/imap

cp courier-imap-1.6.1.20021211.tar.gz /tmp/imap

cp squirrelmail-1.2.9.tar.gz /tmp/imap

cd /tmp/imap


OK now that the files are in our working directory we can start the real fun. We need to unzip and untar the files. We'll start with courier-imap:


gunzip courier-imap-1.6.1.20021211.tar.gz


That should create a file called courier-imap-1.6.1.20021211.tar now you need to untar this:


tar -xf courier-imap-1.6.1.20021211.tar


This will create a directory called courier-imap-1.6.1.20021211. Of course your tar file is still there and there is probably a faster way to get through this process but seein as how I'm still learning Linux this is how I do it. OK, now change to the courier-imap directory and run the following commands:


cd courier-imap-1.6.1.20021211

./configure

make

make check

make install

make install-configure


If all goes well we can then proceed on to the next steps. If you get errors during the above process you will need to refer to the documentation for courier-imap as fixing these errors is beyond the scope of this document and probably beyond the scope of my knowledge unless it's something obvious.


Now, edit /usr/lib/courier-imap/etc/authmysqlrc and change everything there to meet your needs. Here's pieces of my authmysqlrc, just the lines I changed:


MYSQL_SERVER localhost

MYSQL_USERNAME mysqluser <--- This is the mysql user

MYSQL_PASSWORD mysqluser-password <--- This is the password for the mysql user

MYSQL_SOCKET /var/lib/mysql/mysql.sock <--- This Should be the path to yours

# MYSQL_PORT 0 <--- commented this out. Use either mysql.sock or this

MYSQL_DATABASE mailusers <--- This is the mysql database

MYSQL_USER_TABLE passwd <--- This is the table in the mysql database

# MYSQL_CRYPT_PWFIELD crypt <--- commented this out as I use the clear password

MYSQL_CLEAR_PWFIELD clear <--- This is the password field name in the mysql database passwd table

DEFAULT_DOMAIN domain.com <--- Change to your domain name

MYSQL_MAILDIR_FIELD maildir <--- This is the maildir field name in the mysql database passwd table


Now, edit /usr/lib/courier-imap/etc/authdaemonrc. Here's the line I changed:


authmodulelist="authmysql"


Download this file
(create_database.mysql) to create the database, table and user. Once you download the file you have to change 1 thing in the file and that's the password entry. Change this entry to whatever you want the MySQL user password to be. Here's the line in the file, just change the password:

GRANT ALL ON mailusers.* TO courier@localhost IDENTIFIED BY 'password';


After you change the password entry run this:


mysql -uroot -p < create_database.mysql


Now, we need to add users. You can do this now or later but you won't be able to login via squirrelmail until you add users:


mysql -ucourier -ppassword mailusers

INSERT INTO passwd VALUES('user@domain.com','password','full name','0','0','/home/user',

'/var/MailRoot/domains/domain.com/user/Maildir','50000000');

q
<--- This exits from the mysql prompt


For the uid (user ID) and gid (group id)(the 2 numbers after 'full name' and before '/home/user'), you must use the same uid and gid as the user that runs the xmail daemon. If you don't, you will receive permission denied errors from squirrelmail because it doesn't have permission to see the /var/MailRoot/domains/domain.com/user/Maildir directory. I don't know if this is a security issue or not. Maybe someone can fill me in here. Also, the '/home/user' entry can be the '/var/MailRoot/domains/domain.com/user' dir if the user doesn't have an account on the machine.


Now install squirrelmail following the instructions provided with squirrelmail. Once squirrelmail is installed:


cd /path/to/squirrelmail

cd config

perl conf.pl


In the Main Menu pick option # 2 (Server Settings)

Change #4 (Use Sendmail/SMTP) to 'SMTP' (no quotes)

Change #6 (SMTP Server) to 'localhost' (no quotes)

Change #10 (Server) to 'courier' (no quotes)

Change #12 (Delimeter) to '.' (no quotes)

Return to Main Menu

In the Main Menu pick option #3 (Folder Defaults)

Change #1 (Default Folder Prefix) to 'INBOX.' (no quotes, don't forget the period after INBOX)

Change #16 (Auto Create Special Folders) to 'True' (no quotes)

Save Data

Quit


Now, we need to start everything. I assume xmail is already running. If not, start it using:


/etc/rc.d/init.d/xmail start
<--- the path may differ between different Linux distros


Now start the Courier-IMAP server using:


/usr/lib/courier-imap/libexec/imapd.rc start

/usr/lib/courier-imap/libexec/imapd.rc stop
<--- This stops the Courier-IMAP Server


Be sure to add the above line to your startup script along with the stop command. So, now we're ready to test. Login to squirrelmail http://www.yourdomain.com/squirrelmail using the user name you entered into the mysql database earlier. You can login either as user or user@domain.com. If you just use user then @domain.com will be added to the login in the background. If there is already mail for the created user then you should see mail in the squirrelmail inbox, if no mail exists for the user then it will show the folder as empty. You will initially only see the Inbox and Sent folders in squirrelmail. Click the refresh folders link over Inbox and it should create the Drafts and Trash folders for you.


If you have questions, want to rant or whatever, visit the
bulletin board and post there. Hopefully we can get some useful discussion going over there.

Creating/Importing Users into MySql


Unfortunately I'm not very adept at creating shell scripts so at the moment there is no tool to import your existing users into the mysql database. Maybe in the future I can work on providing a script to make this process easier. If anyone would like to contribute a script that would be greatly appreciated.


Special Thanks


I would like to put out a big Thank you to Aaron Johnson who spent many hours over Instant messenging with me and also logged into my server to try and get dbmail to work with XMail on my system. Even though it was unsuccessful I learned a lot about ./configure scripts, folder and file permissions and the way XMail works. Here is a link to Aaron's document for getting XMail, dbmail and squirrelmail to all play together nicely
http://www.gina.net/solution/dbmail_install.html.

Post A Comment

:-D:-o:-p:-(:-):-\:-|:angry::cool::cry::dontknow::emb::hairout::laugh::rolleyes::whew:;-)

Subscribe to keithstric.com

OpenNTF

Disclaimer

The opinions and ideas posted on keithstric.com are not necessarily the opinions and ideas of my employer. The solutions, techniques and code provided here are not guaranteed or warranted in any way and are free for you to use at your own risk.