18 January, 2006

My take on Postfix + Cyrus

The default MTA in SLES9 is Postfix while the default IMAPD is cyrus. Hence, I start to figure out how to use them. By the way, it is really hard to get some good, and in-depth documentation.

Finally, the best document for Cyrus is the official documentation. Besides, I have found two HOW-TO on configuring Postfix + Cyrus on FreeBSD. (But IMO, both of them fail to explain the stuff, anyway, still a good source for me).

  1. The one by Martin
  2. And the one by Francisco Reyes

After all, I've managed to do it. The following is my notes of Postfix + Cyrus + Virtual Host on SLES-9

First, according to /usr/share/doc/packages/cyrus-imapd/README.SuSE, adjust the "lmtpunix" setting in /etc/cyrus.conf.

# --- excerpt of /etc/cyrus.conf

SERVICES {
  # ... [skipped]
  lmtpunix      cmd="lmtpd" listen="/var/spool/postfix/public/lmtp" prefork=1
  # ... [skipped]
}

Sure, you also have to adjust the corresponding path in postfix config, but for now, just continue the rest of Cyrus configuration.

The next step is to adjust the setting in /etc/imapd.conf

# --- excerpt of /etc/imapd.conf 

# you have specify a default domain, esp using virtdomains, 
# it make things more clear. 
defaultdomain: defaultdomain.com 

# enable this option. all cyrus admin command will honour the
# '@virtual.com' part 
virtdomains: on 

# This will enable the use of /etc/sasldb 
# Note, you have do "chown cyrus /etc/sasldb2" 
# I've try to use saslauthd, but seems sasldb2 support 
# isn't enabled in stock saslauthd 
sasl_pwcheck_method: auxprop 

Don't forget to restart cyrus after modified the config files

The next step is using saslpasswd2 to create account in saslpasswd2

  $ saslpasswd2 -c testing -u virtual.com 
  <Enter your password> 

And now, you need to set the password for cyrus (unix account) You have to specify the "admin account" for cyrus imapd. The default in /etc/imapd.conf is "cyrus".

  $ passwd cyrus
  <cyrus' password> 

Switch to "cyrus" account and run cyradm to create mailbox In Cyrus IMAPD, mailbox is not stored in mbox or maildir format. It has it own database format. For each user, you need to create a mailbox, which effectively create the corresponding user (from the point of cyrus imapd).

  $ su - cyrus 
  $ cyradm --user cyrus localhost 

  # it is the cyradm shell 

  # create user mailbox 
  localhost> createmailbox user.testing@virtual.com 

  # grant permissino to global admin 'cyrus' 
  localhost> setacl user.testing@virtual.com cyrus lrswipcda 

  localhost> quit

The Cyrus part of configuration is ready one, you can use normal mail client to connect with it. The client username (login name) is 'testing@virtual.com'.

The rest is configuration for Postfix, basically, we have two aims.

  • It is vhost style config, postfix must handle incoming mail for the domain
  • Make it work with Cyrus (incoming will deliver to cyrus mailbox properly)

The following is the neccessary changes for the main.conf and virtual map file

# --- /etc/postfix/main.conf 

# append the following config at the end of file 
virtual_mailbox_domains = virtual.com 
virtual_mailbox_maps = hash:/etc/postfix/virtual 
virtual_transport = lmtp:unix:/var/spool/postfix/public/lmtp 
# --- /etc/postfix/virtual 

# append the following line at the end of file 
testing@virtual.com     testing@virtual.com 
 # Rebuild the binary map 
 $ postmap /etc/postfix/virtual 

 # Restart postfix 
 $ /etc/init.d/postfix restart 

In the above example, the virtual map file '/etc/postfix/virtual' has only one purpose. When postfix accept an incoming mail, it will verify the incoming user recipient by checking if there is a corresponding entry in virtual map.

No comments: