Postfix would not auto-create the Maildir for incoming mails

email-servermailboxpostfix

I am trying to setup a mail server, I went over tons of tutorials on how to do this with Postfix + dovecot + MySQL, but none was error-proof and I always got stuck at some point with an error, so I decide to configure the mail server step by step by my own, so far I have installed Postfix and ViMbAdmin as my postfix-admin interface, I managed to link the database with Postfix, everything is fine but one! The Postfix would not auto-create the Maildir for incoming mails.

The following is a sample mail.log output for an incoming email:

postfix/smtpd[22086]: connect from mail-lf0-f45.google.com[209.85.215.45]
postfix/smtpd[22086]: C92B461E5B: client=mail-lf0-f45.google.com[209.85.215.45]
postfix/cleanup[22090]: C92B461E5B: message-id=<BLAH@mail.gmail.com>
postfix/qmgr[21732]: C92B461E5B: from=<BLAH-SENDER@gmail.com>, size=4535, nrcpt=1 (queue active)
postfix/virtual[22080]: C92B461E5B: to=<BLAH-RCVR@XXX.net>, orig_to=<BLAH-ALIAS@XXX.net>, relay=virtual, delay=0.13, delays=0.13/0/0/0, dsn=4.2.0, status=deferred (delivery failed to mailbox /var/mail/vhosts/XXX.net/BLAH-RCVR/mail: unable to create lock file /var/mail/vhosts/XXX.net/BLAH-RCVR/mail.lock: No such file or directory)
postfix/smtpd[22086]: disconnect from mail-lf0-f45.google.com[209.85.215.45]

If I manually create the /var/mail/vhosts/XXX.net/BLAH-RCVR/ directory, everything will go fine. I want the application auto-create the directory so I don't have to create it for every user I add to system!

What am I missing in here?


P.S: I've double checked the permission on /var/mail/vhosts/ the postfix should be able to RWX the directory.

Best Answer

I don't know postfix-admin nor ViMbAdmin but creating a maildir is as simple as:

mkdir -p $USERHOME/Maildir/{new,cur,tmp}
chown -R <mail user>,<mail group> $USERHOME/Maildir
chmod -R 700 $USERHOME/Maildir

where $USERHOME is the mailbox home directory (virtual user home directory).

You can write a simple bash script to run every time you create a new mailbox, or you could somehow insert that script in the ViMbAdmin mailbox creation process.

Another solution is to utilize Dovecot LMTP server to deliver local mail, instead of postfix LDA (see Dovecot LMTP documentation). It creates maildirs and has much more features (sieve scripting for example).

Regards

Paolo B.