On Wed, 27 Oct 2021 at 18:27, <dovecot@ptld.com> wrote:
> On 10-27-2021 12:06 pm, Felix Ingram wrote:
>
> user1@foobar.mydomain.com
> user2@foobar.mydomain.com
> user1@barbaz.mydomain.com
> user2@barbaz.mydomain.com
>
> I would like all emails to the "foobar" subdomain to end up in their
> own mailbox and all emails to the "barbaz" subdomain to go to their own
> mailbox.

Your question might be more suited to the postfix mailing list. Dovecot
doesn't receive mail from the internet, which i believe you understand
as you said "have postfix accepting the emails before passing them to
Dovecot".

On the postfix side, one option would be using one mailbox and one
catchall for each subdomain.

    Setup a user: catchall@foobar.mydomain.com
    Setup an alias: @foobar.mydomain.com -> catchall@foobar.mydomain.com

    Setup a user: catchall@barbaz.mydomain.com
    Setup an alias: @barbaz.mydomain.com -> catchall@barbaz.mydomain.com

On the dovecot side, you can setup each person with their own login user
and all of those users access the same IMAP inbox. Or you could just
give everyone the password to the same one mailbox
catchall@foobar.mydomain.com.


So I think this would make sense, though one stumbling block could be that we don't 
know the various subdomains ahead of time. The purpose of the system is that users
can create disposable/temporary email addresses for various testing jobs. The subdomain 
can be any value that the user wants, and we don't want them to have to precreate them before 
they can use an address (we have an existing system that works this way, and so we want to 
keep that behaviour). I think your approach would work, however, if I set up aliases similar to:

@barbaz.mydomain.com -> barbaz@mydomain.com.

I believe I can do that in postfix with some regex magic.
I would then want users to log in as "barbaz", and get access to all of the emails. I believe that
if I create Dovecot users for my system users, and then set them as master users, then they will 
be able to log into Dovecot with something like:

barbaz*<system user account>

as their username.


Not sure "dovecot creating users" is the right way to think about it.
Dovecot simply looks for IMAP files where its told to look. In dovecot
config you setup flat files or databases that tell dovecot if someone
logs in with this user:pass then look in this /server/path for emails.
Other than that config, which you could point to a different
/server/path changing their inbox, there are no "accounts".

I think my "creating users" was me wanting to make sure that when postfix passes an email for
"barbaz@mydomain.com" to Dovecot, then Dovecot will store it and wait for someone to come along
and impersonate barbaz. i.e. "barbaz" doesn't have to exist as a user already before Dovecot will store the
mail.

Thanks again for the pointers - I shall play with postfix local delivery before trying to wire up Dovecot.

Regards,

Felix