Dovecot: separate inboxes by domain

Dear FreeBSD users,

I am running a mail server with OpenBSD opensmtpd for mail delivery and Dovecot for IMAP access. The server accepts mail for two domains, let's call them domain1 and domain2. Users authenticate against the system /etc/passwd file, meaning they log in to SMTP/IMAP only using username rather than username@domainX.

opensmtpd can match domains when delivering mail, meaning I have control over where I store it. The problem arises with IMAP access, though. Because the users authenticate only with username, the domain login variable is empty, meaning I cannot differentiate between users accessing domain1 or domain2. For now, both domains use a shared inbox, which works, but is not what I'd like.

Is there any simple way for getting Dovecot to access different mailboxes, depending on the domain one connects two? The domains have separate MX entries, like mail.domain1.net and mail.domain2.net.
 
If I understand correctly, you have authentification via /etc/passwd you don't need to use a domain in your dovecot config, according to this . So, dovecot will use only a username to authenticate and access to mailbox (mailbox path dovecot gets from /etc/passwd according to this ). Could you provide more details, for example errors when you try to access mailbox?
 
Ah, a simpler solution in those links...

Check the bottom of the page here

I assume your current situation has the passdb entry look similar. Have the userdb query accept the domain (%Ld) and return a different "home" directory based on the query (/mail/domain2.net/user) or /mail/%Ld/%Lu

I usually do this in SQLite but you could just use the static driver like so

Code:
userdb {
    driver = static
    args = uid=500 gid=500 home=/mail/%Ld/%Lu
}

You will have to change how the users login, though, by making the username the full email. HOWEVER... If you don't want to do that, you can manually assign the paths in the userdb, but you can not have the same user across domains.

Use the passwd-file driver for userdb and have the file specified look like this (changing out 500:500 for the userid and group id of the mail user)

Code:
user:{plain}doesnt_matter_not_used:500:500::/mail/domain2.net/user
user2:{plain}doesnt_matter_not_used:500:500::/home/domain1.net/user2

Then point the userdb at that file
Code:
userdb {
      driver = passwd-file
      args = username_format=%Ln /etc/dovecot/userdb.passwd
      default_fields = uid=vmail gid=vmail home=/mail/domain1.net/%Lu
}

I use the %L to default lowercase things so they don't get messed up.
 
If I understand correctly, you have authentification via /etc/passwd you don't need to use a domain in your dovecot config, according to this . So, dovecot will use only a username to authenticate and access to mailbox (mailbox path dovecot gets from /etc/passwd according to this ). Could you provide more details, for example errors when you try to access mailbox?
There are no errors, perhaps I was not clear enough. The issue is that, by accessing my mail through two different domains, I always reach the same inbox. And so I have to have my mail for different domains flowing into the same inbox.

I can easily configure OpenBSD smtpd to put mail in different places for different domains, but Dovecot is not so easy to handle.
 
auth_username_format = %Ln
................................................
namespace private {
......................................
location = /home/%n/%{auth_domain}/Maildir
...
}
this works for me
it will log you in with anything as domain but will bomb (disconnect client if no mailbox exists)
i created an empty Maildir in ~/tmp and it works if i log in as foo@tmp
if i login as foo it uses my regular Maildir
 
Back
Top