What the message looks like
dovecot: imap(user@example.com): Error: open(/var/mail/user) failed: Permission denied (euid=1000(user) egid=1000(user) missing +w perm: /var/mail, dir owned by 0:8 mode=0775)Common causes
- The mail files belong to another user than the one Dovecot uses, for example after copying as root.
mail_locationpoints to the wrong path, or the directory does not exist.mail_uid,mail_gidorfirst_valid_uiddo not match the real owner.- The system mailbox
/var/mailneeds the mail group, which Dovecot does not have. - SELinux or AppArmor blocks access to the mail directory.
Check
- Which location and user settings are active?
doveconf -n | grep -E 'mail_location|mail_uid|mail_gid|first_valid_uid' - Who owns the mail directory?
ls -ld /var/mail /var/vmail - What does Dovecot think for this account?
doveadm user user@example.com - The exact errors
Fix
- Set the right location, for example
mail_location = maildir:/var/vmail/%d/%normaildir:~/Maildir. - Fix the owner:
chown -R vmail:vmail /var/vmailandchmod -R u+rwX,g-rwx,o-rwx /var/vmail. - Make
mail_uidandmail_gidmatch that owner, andfirst_valid_uidlower than it. - For
/var/mail, setmail_privileged_group = mailso Dovecot can create lock files. - Reload:
doveadm reloadand test the login again.
FAQ
Why does it work for new mail but not for old mail?
Old files were created by another user or tool. Fix the owner for the whole mail tree, not only for new folders.
Do Postfix and Dovecot have to use the same user?
For local delivery, the user who writes the files and the user who reads them must be able to access the same files. A virtual mail user such as vmail for both is the simplest setup.