The following assumes your using Dovecot SMTP Auth and a version of Postfix that supports it. > 2.3 (I think)
Create a virtual mail user, make the directory for the virtual mail, and make it owned by the vmail account.
Code:
groupadd -g 5000 vmail
useradd -m -u 5000 -g 5000 -s /bin/bash vmail
mkdir /var/mail/vmail
chown vmail:vmail /var/mail/vmail
/etc/postfix/main.cf
Code:
# DELIVERY TO MAILBOX
#
# The home_mailbox parameter specifies the optional pathname of a
# mailbox file relative to a user's home directory. The default
# mailbox file is /var/spool/mail/user or /var/mail/user. Specify
# "Maildir/" for qmail-style delivery (the / is required).
#
home_mailbox = Maildir/
# Virtual mail users
virtual_mailbox_base = /var/mail/vmail
virtual_mailbox_domains = /etc/postfix/virtual/vdomains.txt
virtual_mailbox_maps = hash:/etc/postfix/virtual/vmailboxes.txt
virtual_minimum_uid = 1000
virtual_uid_maps = hash:/etc/postfix/virtual/vuid.txt
virtual_gid_maps = hash:/etc/postfix/virtual/vgid.txt
virtual_alias_maps = hash:/etc/postfix/virtual/valias.txt
The "home_mailbox = Maildir/" above allows both local and virtual users to work without permission problems.
Local mails are in: /home/user/Maildir
Virtual mails are in: /var/mail/vmail/domain.xxx/user/Maildir/
/etc/postfix/virtual/domains
Code:
domain.xxx
xxx above can be com / org / net or whatever you own.
/etc/postfix/virtual/domains/domain.xxx
Code:
# Maildir mail addresses for domain.xxx
user1@domain.xxx domain.xxx/user1/Maildir/
user2@domain.xxx domain.xxx/user2/Maildir/
# Comment out the entry below to implement a catch-all.
# @domain.xxx domain
/etc/postfix/virtual/uids/domain
Code:
# Domains owned by local user domain (uid/gid) 1000:1000
#@domain.com 1000
@domain.xxx 5000
#@domain.net 1000
#@domain.org 1000
The 1000's above are part of an incomplete experiment to move virtual mail to the local system owner of the virtual domain from:
/var/mail/vmail/domain.xxx
to
/home/localuser/Maildir/domain.xxx/user/Maildir
/etc/postfix/build-mail.sh
Code:
#!/bin/sh
# Create the list of domains
ls /etc/postfix/virtual/domains > /etc/postfix/virtual/vdomains.txt
# Create the virtual mailboxes
cat /etc/postfix/virtual/domains/* > /etc/postfix/virtual/vmailboxes.txt
postmap /etc/postfix/virtual/vmailboxes.txt
# Create the virtual aliases
cat /etc/postfix/virtual/aliases/* > /etc/postfix/virtual/valiases.txt
postmap /etc/postfix/virtual/valiases.txt
# Create the list of domain uids
cat /etc/postfix/virtual/uids/* > /etc/postfix/virtual/vuid.txt
postmap /etc/postfix/virtual/vuid.txt
# Create the list of domain gids
cat /etc/postfix/virtual/uids/* > /etc/postfix/virtual/vgid.txt
postmap /etc/postfix/virtual/vgid.txt
# The final step is to create the mailboxes for the users.
# Thanks to the magic of permissions this will happen auto-magically when the account first gets mail
The above is a quick build and postmap all the files.