For virtual users you need to create a system user account and have it own the mails, and then configure that user's UID & GID in Postfix and Dovecot.
Here are the relevant parts of my dovecot.conf
:
userdb {
driver = static
args = uid=8 gid=12 home=/var/spool/mail/%n
}
mail_location = maildir:~
mail_uid = 8
mail_gid = 12
The userdb is a really simple passwd-like file with just usernames and passwords and everything else is hardcoded in the actual userdb {...}
block above, so UID and GID, and the "home" of the user is in /var/spool/mail
and starts with whatever login was used (assuming it was defined in the passwd file beforehand, otherwise access will be denied).
mail_location
tells it that mails are in maildir format and located in ~
(home), which corresponds to the "home" path it got from the userdb above.
mail_gid/uid
again set the ownership of the mails to the corresponding system user that should own the mails; it should obviously be the same in Postfix.
Postfix main.cf
:
virtual_mailbox_base = /var/spool/mail
virtual_mailbox_maps = hash:/etc/postfix/vmailboxes
virtual_uid_maps = static:8
virtual_gid_maps = static:12
Same base directory as Dovecot, the /etc/postfix/vmailboxes
just has the syntax <mail user account> <mail directory>/
so for example if it contains serverfault serverfault/
that tells Postfix that any mail received to serverfault@domain
would end up in /var/spool/mail/serverfault
, which corresponds to where Dovecot will look for them when you log in with the serverfault
username.
The virtual_uid/gid_maps
are again to set the ownership of the mails to the system user we choose/created beforehand, it should be the same as Dovecot.
I don't know of any particular options for logging required to display errors, if I mess up the permissions of the virtual mail folder my Dovecot starts screaming in the logs without any special configuration (no logging-related options in my dovecot.conf) :
Mar 07 12:54:04 sanctuary dovecot[2175]: imap(username): Error: chdir(/var/spool/mail/username/) failed: Permission denied (euid=8(mail) egid=12(mail) missing +x perm: /var/spool/mail/username, dir owned by 0:0 mode=0700)
Mar 07 12:54:04 sanctuary dovecot[2175]: imap(username): Error: chdir(/var/spool/mail/username) failed: Permission denied
Mar 07 12:54:04 sanctuary dovecot[2175]: imap(username): Error: opendir(/var/spool/mail/username) failed: Permission denied (euid=8(mail) egid=12(mail) missing +r perm: /var/spool/mail/username)
Mar 07 12:54:04 sanctuary dovecot[2175]: imap(username): Error: opendir(/var/spool/mail/username) failed: Permission denied (euid=8(mail) egid=12(mail) missing +r perm: /var/spool/mail/username)
Mar 07 12:54:04 sanctuary dovecot[2175]: imap(username): Error: stat(/var/spool/mail/username/tmp) failed: Permission denied (euid=8(mail) egid=12(mail) missing +x perm: /var/spool/mail/username, dir owned by 0:0 mode=0700)
Mar 07 12:54:04 sanctuary dovecot[2175]: imap(username): Error: stat(/var/spool/mail/username/tmp) failed: Permission denied (euid=8(mail) egid=12(mail) missing +x perm: /var/spool/mail/username, dir owned by 0:0 mode=0700)
Mar 07 12:54:04 sanctuary dovecot[2175]: imap(username): Error: stat(/var/spool/mail/username/tmp) failed: Permission denied (euid=8(mail) egid=12(mail) missing +x perm: /var/spool/mail/username, dir owned by 0:0 mode=0700)
Mar 07 12:54:09 sanctuary dovecot[2175]: imap(username): Error: chdir(/var/spool/mail/username/) failed: Permission denied (euid=8(mail) egid=12(mail) missing +x perm: /var/spool/mail/username, dir owned by 0:0 mode=0700)
Mar 07 12:54:09 sanctuary dovecot[2175]: imap(username): Error: chdir(/var/spool/mail/username) failed: Permission denied
Mar 07 12:54:09 sanctuary dovecot[2175]: imap(username): Error: stat(/var/spool/mail/username/.Sent Messages/tmp) failed: Permission denied (euid=8(mail) egid=12(mail) missing +x perm: /var/spool/mail/username, dir owned by 0:0 mode=0700)
Mar 07 12:54:09 sanctuary dovecot[2175]: imap(username): Error: stat(/var/spool/mail/username/tmp) failed: Permission denied (euid=8(mail) egid=12(mail) missing +x perm: /var/spool/mail/username, dir owned by 0:0 mode=0700)
Mar 07 12:54:09 sanctuary dovecot[2175]: imap(username): Error: stat(/var/spool/mail/username/.Sent Messages/tmp) failed: Permission denied (euid=8(mail) egid=12(mail) missing +x perm: /var/spool/mail/username, dir owned by 0:0 mode=0700)
Mar 07 12:54:09 sanctuary dovecot[2175]: imap(username): Error: stat(/var/spool/mail/username/tmp) failed: Permission denied (euid=8(mail) egid=12(mail) missing +x perm: /var/spool/mail/username, dir owned by 0:0 mode=0700)
Mar 07 12:54:10 sanctuary dovecot[2175]: imap(username): Error: stat(/var/spool/mail/username/.Sent Messages/tmp) failed: Permission denied (euid=8(mail) egid=12(mail) missing +x perm: /var/spool/mail/username, dir owned by 0:0 mode=0700)
Mar 07 12:54:10 sanctuary dovecot[2175]: imap(username): Error: stat(/var/spool/mail/username/tmp) failed: Permission denied (euid=8(mail) egid=12(mail) missing +x perm: /var/spool/mail/username, dir owned by 0:0 mode=0700)
Same with Postfix when I attempt to send an email with the permissions messed up :
Mar 07 12:56:45 sanctuary postfix/virtual[2736]: warning: maildir access problem for UID/GID=8/12: create maildir file /var/spool/mail/username/tmp/1425729405.P2736.sanctuary: Permission denied
Mar 07 12:56:45 sanctuary postfix/virtual[2736]: warning: perhaps you need to create the maildirs in advance
Mar 07 12:56:45 sanctuary postfix/virtual[2736]: E752F186: to=<username@sanctuary>, relay=virtual, delay=0.05, delays=0.03/0.01/0/0.01, dsn=4.2.0, status=deferred (maildir delivery failed: create maildir file /var/spool/mail/username/tmp/1425729405.P2736.sanctuary: Permission denied)