0

I am trying to set up a relatively basic postfix/dovecot IMAP/SMTP server with a MySQL backend. It appears that the authentication is successful, I just seem to be getting this error:

Initialization failed: Namespace '': Home directory not set for user. Can't expand ~/ for mail root dir in: ~/myserver.io/mail/

The error I am getting is this, along with DEBUG:

Feb  8 04:27:13 localhost dovecot: auth: Debug: Loading modules from directory: /usr/lib64/dovecot/auth
Feb  8 04:27:13 localhost dovecot: auth: Debug: Module loaded: /usr/lib64/dovecot/auth/libdriver_mysql.so
Feb  8 04:27:13 localhost dovecot: auth: Debug: Module loaded: /usr/lib64/dovecot/auth/libdriver_sqlite.so
Feb  8 04:27:13 localhost dovecot: auth: Debug: Read auth token secret from /var/run/dovecot/auth-token-secret.dat
Feb  8 04:27:13 localhost dovecot: auth: Debug: auth client connected (pid=9974)
Feb  8 04:27:13 localhost dovecot: auth: Debug: client in: AUTH#0111#011PLAIN#011service=imap#011secured#011session=IeV306tkgAB/AAAB#011lip=127.0.0.1#011rip=127.0.0.1#011lport=143#011rport=50816#011resp=AG1haWxAdmVuZ2VhbmNlLmlvAENyM2F0MXZlLS0= (previous base64 data may contain sensitive data)
Feb  8 04:27:13 localhost dovecot: auth-worker(9977): Debug: Loading modules from directory: /usr/lib64/dovecot/auth
Feb  8 04:27:13 localhost dovecot: auth-worker(9977): Debug: Module loaded: /usr/lib64/dovecot/auth/libdriver_mysql.so
Feb  8 04:27:13 localhost dovecot: auth-worker(9977): Debug: Module loaded: /usr/lib64/dovecot/auth/libdriver_sqlite.so
Feb  8 04:27:13 localhost dovecot: auth-worker(9977): Debug: sql([email protected],127.0.0.1): query: SELECT username, domain, password, CONCAT('maildir:~/', maildir) AS userdb_home, '1000' AS userdb_uid, '1000' AS userdb_gid FROM mailbox WHERE username = 'mail' AND domain = 'myserver.io'
Feb  8 04:27:13 localhost dovecot: auth: Debug: client passdb out: OK#0111#[email protected]
Feb  8 04:27:13 localhost dovecot: auth: Debug: master in: REQUEST#0112229403649#0119974#0111#011aaa130ec6f6296678ec1e9e7866efbaf#011session_pid=9980#011request_auth_token
Feb  8 04:27:13 localhost dovecot: auth-worker(9977): Debug: sql([email protected],127.0.0.1): SELECT CONCAT('maildir:~/', maildir) as mail, '1000' AS uid, '1000' as gid FROM mailbox WHERE username = 'mail' AND domain = 'myserver.io'
Feb  8 04:27:13 localhost dovecot: auth: Debug: master userdb out: USER#0112229403649#[email protected]#011mail=maildir:~/myserver.io/mail/#011uid=1000#011gid=1000#011auth_token=d72ede03452694f33b4b1c759539f7ec613cab95
Feb  8 04:27:13 localhost dovecot: imap-login: Login: user=<[email protected]>, method=PLAIN, rip=127.0.0.1, lip=127.0.0.1, mpid=9980, secured, session=<IeV306tkgAB/AAAB>
Feb  8 04:27:13 localhost dovecot: imap: Debug: Added userdb setting: mail=maildir:~/myserver.io/mail/
Feb  8 04:27:13 localhost dovecot: imap([email protected]): Debug: Effective uid=1000, gid=1000, home=
Feb  8 04:27:13 localhost dovecot: imap([email protected]): Debug: Namespace inbox: type=private, prefix=, sep=/, inbox=yes, hidden=no, list=yes, subscriptions=yes location=maildir:~/myserver.io/mail/
Feb  8 04:27:13 localhost dovecot: imap([email protected]): Error: user [email protected]: Initialization failed: Namespace '': Home directory not set for user. Can't expand ~/ for mail root dir in: ~/myserver.io/mail/
Feb  8 04:27:13 localhost dovecot: imap([email protected]): Error: Invalid user settings. Refer to server log for more information.
p=/, inbox=yes, hidden=no, list=yes, subscriptions=yes location=maildir:~/myserver.io/mail/

My dovecot config is:

[root@postfix webmail]# dovecot -n
# 2.2.10: /etc/dovecot/dovecot.conf
# OS: Linux 4.14.14-x86_64-linode94 x86_64 CentOS Linux release 7.4.1708 (Core)
auth_debug_passwords = yes
disable_plaintext_auth = no
mail_debug = yes
mail_gid = vmail
mail_privileged_group = mail
mail_uid = vmail
namespace inbox {
  inbox = yes
  location =
  mailbox Drafts {
    auto = subscribe
    special_use = \Drafts
  }
  mailbox Junk {
    auto = subscribe
    special_use = \Junk
  }
  mailbox Sent {
    auto = subscribe
    special_use = \Sent
  }
  mailbox Trash {
    auto = subscribe
    special_use = \Trash
  }
  prefix =
  separator = /
  type = private
}
passdb {
  args = /etc/dovecot/dovecot-sql.conf
  driver = sql
}
protocols = imap
service auth {
  unix_listener /var/spool/postfix/private/auth {
    group = postfix
    mode = 0660
    user = postfix
  }
  unix_listener auth-master {
    group = vmail
    mode = 0660
    user = vmail
  }
  user = $default_internal_user
}
ssl = no
userdb {
  args = /etc/dovecot/dovecot-sql.conf
  driver = sql
}

Finally, my MySQL conf

driver = mysql
# The mysqld.sock socket may be in different locations in different systems.
# Use "host= ... pass=foo#bar" with double-quotes if your password has '#' character.
connect = host=localhost dbname=postfix user=root password=supersecretpass
default_pass_scheme = MD5-CRYPT

# Alternatively you can connect to localhost as well:
#connect = host=localhost dbname=mails user=admin password=pass # port=3306

password_query = SELECT username, domain, password, \
                 CONCAT('maildir:~/', maildir) AS userdb_home, \
                 '1000' AS userdb_uid, '1000' AS userdb_gid \
                 FROM mailbox WHERE username = '%n' AND domain = '%d'

user_query = SELECT CONCAT('maildir:~/', maildir) as mail, '1000' AS uid, '1000' as gid FROM mailbox WHERE username = '%n' AND domain = '%d'

# For using doveadm -A:
iterate_query = SELECT username, domain FROM mailbox

I am at a complete loss!

2
  • Your user_query doesn't return the user's home directory.
    – Torin
    Feb 8, 2018 at 8:06
  • You write "Finally, my MySQL conf" but I think you mean "my dovecot-sql.conf"? Besides that, Torin Carey has hit the nail on its head.
    – wurtel
    Feb 8, 2018 at 10:47

1 Answer 1

1

The error is pretty clear:

Error: user [email protected]: Initialization failed: Namespace '': Home directory not set for user. Can't expand ~/ for mail root dir in: ~/myserver.io/mail/

Dovecot doesn't know where to put the mail, because you have set the maildir to be ~/myserver.io/mail/ but you have not told it what the user's home directory is. Try something like this, which sets the home as well as userdb_mail:

password_query = SELECT username, domain, password, \
             FROM mailbox WHERE username = '%n' AND domain = '%d' 
user_query     = SELECT CONCAT('maildir:~/', maildir) as userdb_mail,\
             CONCAT('/home/', username) as home,\
             '1000' AS uid, '1000' as gid \
             FROM mailbox WHERE username = '%n' AND domain = '%d'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .