Postfix-Cyrus-Web-cyradm-HOWTO

Luc de Louw

           luc@delouw.ch
        

Revision History
Revision 1.0.02002-04-07Revised by: ldl
Initial Release

Table of Contents
1. Introduction
1.1. Contributors and Contacts
1.2. Why I wrote this document
1.3. Copyright Information
1.4. Disclaimer
1.5. New Versions
1.6. Credits
1.7. Feedback
1.8. Translations
2. Technologies
2.1. The Postfix MTA
2.2. Cyrus IMAP
2.3. MySQL Database
2.4. pam_mysql
2.5. Web-cyradm Webinterface
3. Getting and installing the software
3.1. Getting and installing MySQL
3.2. Getting and installing Postfix
3.3. Getting and installing Cyrus IMAP
3.4. Getting and installing pam_mysql
3.5. Getting and installing Web-cyradm
4. Configuration
4.1. Configuring MySQL
4.2. Configuring PAM
4.3. Configuring Postfix
4.4. Configuring Cyrus IMAP
4.5. Configuring Web-cyradm
5. Testing the setup
5.1. (Re-)Starting the daemons
5.2. Testing Web-cyradm
5.3. Testing postfix
5.4. Testing the IMAP and POP functionality
6. Further Information
6.1. News groups
6.2. Mailing Lists
6.3. HOWTO
6.4. Local Resources
6.5. Web Sites
7. Questions and Answers

1. Introduction


2. Technologies


3. Getting and installing the software

Most of the software is included in your Linux distribution. SuSE is shipping Cyrus as far as I know since 7.1 and Redhat at least since recent time.

I suggest you to install Cyrus and SASL as binary from rpm. Postfix is needed to compile by yourself because the lack of MySQL support by the rpm's from the distributors.


3.1. Getting and installing MySQL


3.1.2. Building and installing

cd /usr/local
tar -xvzf mysql-3.23.49a.tar.gz
cd mysql-3.23.49a

./configure \
--prefix=/usr/local/mysql \
--enable-assembler \
--with-innodb

make
make install

/usr/local/mysql/bin/mysql_install_db
echo /usr/local/mysql/lib/mysql >> /etc/ld.so.conf
ldconfig

For security-improvement add a mysql-user on your system i.e. "mysql", then

chown -R mysql /usr/local/mysql/var

and change the line user=root to user=mysql in the file /usr/local/mysql/bin/safe_mysqld

you may wish to start mysql automatically at boottime, copy /usr/local/mysql/share/mysql/mysql.server to /etc/init.d/ for SuSE and Redhat. Further you need to add Symlinks to /etc/init.d/rc3.d for SuSE and /etc/rc.d/rc3.d

The following example is for SuSE Linux and should be easily changed for Redhat and other Linux distributions and commercial Unixes.

cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/
ln -s /etc/init.d/mysql.server /etc/init.d/rc3.d/S20mysql
ln -s /etc/init.d/mysql.server /etc/init.d/rc3.d/k08mysql

3.5. Getting and installing Web-cyradm


3.5.2. Installing

Web-cyradm is written in PHP. If you don't have a webserver with php installed, I like to refer to my Apache-Compile-HOWTO. That document describes how to set up Apache with PHP and other modules

cd /usr/local/apache/htdocs

tar -xvzf web-cyradm-latest.tar.gz

After unpacking web-cyradm move it to a place in your webservers DocumentRoot

This is all, now we need to configure the whole bunch of software


4. Configuration

4.1. Configuring MySQL


4.2. Configuring PAM

Now we need to get sure that PAM knows how to authenticate the Cyrus users

You have to create the file /etc/pam.d/imap with the following entries:

auth sufficient pam_mysql.so user=mail passwd=secret host=localhost db=mailadmin table=accountuser usercolumn=username   passwdcolumn=password crypt=0

auth sufficient pam_unix_auth.so

account required pam_mysql.so user=mail passwd=secret host=localhost db=mail table=accountuser usercolumn=username passwdcolumn=password   crypt=0

account  sufficient       pam_unix_acct.so

The lines containing pam_unix_auth.so and pam_unix_acct.so are only needed if you are migrating from wu-IMAP to cyrus. This way the users can be authenticate with its old unix-password and its new mysql-based password

If you will use Cyrus also for POP-Service just cp /etc/pam.d/imap /etc/pam.d/pop


4.3. Configuring Postfix

Postfix needs two major config files: main.cf and master.cf. Both needs now our attention.


4.3.1. master.cf

You need to change just one line:

old:

argv=/cyrus/bin/deliver 

new:

argv=/usr/cyrus/bin/deliver

4.3.2. main.cf

Here you need to change some more things like hostname, relaying, alias-lookups etc.

First change hostname:

myhostname = foo.bar.org

mydestination

Here you have to put all domainnames that are local (corresponding to sendmail's /etc/mail/sendmail.cw) If you have multiple domains separate them with comma

mydestination = foo.bar.org, example.com, furchbar-grausam.ch, whatever.domain.tld

relayhost

Here you define where to deliver outgoing mails. If you do not provide any host. mails are delivered directly to the destination smtp host. Usually your relayhosts are your providers smtp-server

relayhost = relay01.foobar.net relay02.foobar.net relay03.foobar.net

mailtransport

Here you define how the mails accepted for local delivery should be handled. In our situation mails should be delivered by the cyrus delivery-program

mailbox_transport = cyrus

At the end of file you need to add:

virtual_maps = hash:/etc/postfix/virtual, mysql:/etc/postfix/mysql-virtual.cf

Outgoing addresses should be rewritten from i.e test0002@domain to user.name@virtualhost.com. This is important if you like to use a webmail interface.

sender_canonical_maps = mysql:/etc/postfix/mysql-canonical.cf 

Now you need to create the file /etc/postfix/mysql-virtual.cf:

#
# mysql config file for alias lookups on postfix
# comments are ok.
#

# the user name and password to log into the mysql server
hosts = localhost
user = mail
password = secret

# the database name on the servers
dbname = mailadmin

# the table name
table = virtual

#
select_field = dest
where_field = alias
additional_conditions = and status = '1'

And the file /etc/postfix/mysql-canonical.cf:

# mysql config file for canonical lookups on postfix
# comments are ok.
#

# the user name and password to log into the mysql server
hosts = localhost
user = mail
password = secret

# the database name on the servers
dbname = mail

# the table name
table = virtual
#
select_field = alias
where_field = username
# Return the first match only
additional_conditions = and status = '1' limit 1

4.4. Configuring Cyrus IMAP

There is only little changes needed. Edit /etc/imapd.conf and take care that the following entry is done

    sasl_pwcheck_method: pam

This tells the Cyrus IMAP to authenticate using PAM

If you want to enable Cyrus' TLS/SSL facilities you have to create a certificate first. This requires an OpenSSL installation

openssl req -new -nodes -out req.pem -keyout key.pem  
openssl rsa -in key.pem -out new.key.pem
openssl x509 -in req.pem -out ca-cert -req \
-signkey new.key.pem -days 999 

cp new.key.pem /var/imap/server.pem

echo tls_cert_file: /var/imap/server.pem >> /etc/imapd.conf
echo tls_key_file: /var/imap/server.pem >> /etc/imapd.conf

If you like to use sieve (A Mail Filtering Language), you must change an entry in /etc/services. Add or change the following line:

sieve           2000/tcp

5. Testing the setup


5.2. Testing Web-cyradm

Now you should be able to connect to http://localhost/mailadmin/ Login with the credentials defined before.

Define a Domainname and some accounts. Be sure the domainname belongs to your server. If not you have to fake it by enter the domain in /etc/hosts. The Domain must also be defined as local in /etc/postfix/main.cf (mydestination = domain)


5.3. Testing postfix

Now we are going to write a mail:

telnet localhost 25
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 mail ESMTP Postfix

helo localhost
250 mail
mail from: luc@delouw.ch
250 Ok
rcpt to: rcpt to: luc@localhost
250 Ok

data
354 End data with <CR><LF>.<CR><LF>
some text
.
250 Ok: queued as B58E141D33

quit

If you see such a message, then all seems to work fine. Be sure to specify a recipients address you previously defined in the web-cyradm database

If you get an error like this:

rcpt to: luc@localhost
451 <luc@localhost>: Temporary lookup failure

Then eighter MySQL is not running, DB permission are not set properly or you miss-configured /etc/postfix/main.cf

On any errors, I suggest to examine /var/log/mail. Often you will find some hints whats went wrong.


6. Further Information

Here you will find some other resources available in the internet


6.1. News groups

Some of the most interesting news groups are:

Maybe you also check out your country newsgroups e.g ch.comp.os.linux

Most newsgroups have their own FAQ that are designed to answer most of your questions, as the name Frequently Asked Questions indicate. Fresh versions should be posted regularly to the relevant newsgroups. If you cannot find it in your news spool you could go directly to the FAQ main archive FTP site. The WWW versions can be browsed at the FAQ main archive WWW site.


6.2. Mailing Lists


6.2.1.

Send an mail to with the content (not subject):
subscribe postfix-users

Before writing to the list, check out the archive: http://www.deja.com/group/mailing.postfix.users


6.2.2.

Send an mail to with the content (not subject):
subscribe info-cyrus

Before writing to the list, check out the archive: http://asg.web.cmu.edu/archive/index.php?mailbox=archive.info-cyrus


6.5. Web Sites

There are a huge number of informative web sites available. By their very nature they change quickly so do not be surprised if these links become quickly outdated.

A good starting point is of course the Linux Documentation Project home page, an information central for documentation, project pages and much more.

To get more deepened information about Postfix, then www.postfix.org would be the starting point.

Please let me know if you have any other leads that can be of interest.


7. Questions and Answers

Here I answer the questions which I got from users. If you don't find an answer feel free to contact me