Setting up Postfix and Dovecot with virtual mailboxes
Postfix
- Create a user to access the virtual mailboxes:
# groupadd -g 1000 virtual # useradd -M -u 1000 -g virtual -s /sbin/nologin -d /var/mail/vhosts virtual
- Relevent lines from main.cf:
virtual_mailbox_domains = example.com, example.net virtual_alias_maps = hash:/etc/postfix/virtual_alias virtual_mailbox_base = /var/mail/vhosts virtual_mailbox_maps = hash:/etc/postfix/vmailbox virtual_uid_maps = static:1000 virtual_gid_maps = static:1000
- Create the directory for the virtual mailboxes
# mkdir /var/mail/vhosts
- Under here we have another directory for each domain we handle:
# mkdir /var/mail/vhosts/example.com # mkdir /var/mail/vhosts/example.net
- Under these domains we have the mailboxes for each user. They should be owned by the virtual user:
# mkdir /var/mail/vhosts/example.com/bob
- Contents /etc/postfix/vmailbox:
# Comment out the entry below to implement a catch-all. # @example.com example.com/catchall # Remember the trailing slash for Maildir format! # example.com bob@example.com example.com/bob/ # example.net alice@example.net example.net/alice/
Dovecot
The dovecot RPM has a MySQL dependency. This can be a problem if you use the MySQL official RPMs because they have a different name from the Fedora supplied RPMs. To get around this I modified the src RPM spec file and rebuilt the RPM to use the MySQL official RPMs (and I also removed PostgreSQL support):
Download the dovecot src RPM from ATrpms.net
- Install the src RPM:
# rpm -Uvh dovecot-1.0-3_51.rc28.at.src.rpm
- Edit the spec file to remove Postgres and change MySQL package name:
%define build_postgres 0 BuildRequires: MySQL-devel
- Rebuild the package and install it:
# rpmbuild --without inotify -ba dovecot.spec # rpm -Uvh dovecot-1.0-3_51.rc28.i386.rpm
- Generate SSL certificate by editing /etc/pki/dovecot/dovecot-openssl.cnf and running /usr/share/doc/dovecot-1.0/mkcert.sh
- Relevent lines from dovecot.conf:
mail_location = maildir:/var/mail/vhosts/%d/%n
# passwd-like file with specified location
# http://wiki.dovecot.org/AuthDatabase/PasswdFile
passdb passwd-file {
# Path for passwd-file
args = /etc/dovecot/passwd
}
# passwd-like file with specified location
# http://wiki.dovecot.org/AuthDatabase/PasswdFile
userdb passwd-file {
# Path for passwd-file
args = /etc/dovecot/users
}
- The format of the passdb file:
foo@example.com:{md5}dhf83jS64hgowkgj34jdhfjsdf
- The format of the userdb file:
foo@example.com::1000:1000::/var/mail/vhosts/example.com/:/bin/false::
- Make sure these files are only readable by root
- Users should be able to login using their email address as username.
