Using Dovecot’s LMTP with virtual users (with db lookup to map address to mailbox)

dovecotemailmailbox

I'd like to use dovecot with sql-based virtual users (which already works fine in my current exim+courier-imapd setup).

In my setup there are "mailboxes" which have a mailboxname@domain and a password. Besides that, there are "addresses" which map actual email addresses to mailboxes.
When logging in via IMAP or POP3 users use the mailbox name and password. So I simply check the mailbox table in the dovecot passdb query which works fine.

The userdb query is kind of a problem though: When a user logs in, the available information is obviously the mailboxname@domain username which can then be used to create the mailbox path (even possible with a static userdb).
When an email is delivered via LMTP, however, I need to query the addresses table to retrieve the destination mailbox – so I'd need a different query in this case.


One possible solution would probably be using some conditionals on the DB level which execute different queries depending on the %s variable (service name, e.g. lmtp) – but obviously that'd be a huge mess.

Another solution might be simply using LDA instead of LMTP as I can them perform the lookup of the mailbox name in exim and simply pass it to the LDA program – but using LDA not only involves an additional process being launched (not that it matters on my low-volume server, but anyway) and probably worse error handling as LDA can only return exit status codes to exim unlike LMTP which probably returns a verbose error message.

So I'd like to know if there's a way to perform different userdb queries depending on where they are used – in a delivery or when accessing a mailbox.

Best Answer

Dovecot LMTP is wholly unrelated to the IMAP server (and its concomitant login and userdb).

However, ttbomk there is no way to log in/deliver mail using one user and accept mail using another (or an alias).

In postfix, this is trivial to solve by adding a virtual alias map containing the recipient addresses and the LMTP users; this is really not something an LDA should do.