Automatically Creating Mailboxes

Hope you’re all doing okay and safe from covid. It’s giving me time to get around to things I have been putting off doing. Which brings us to the reason for this post…

I would like to automatically create a mailbox whenever I receive an email for an address that doesn’t exist yet, IF, the address contains a postfix.


Once created I would like the mailbox to forward mail to my main mailbox.

The idea is I can then create throw away email addresses for all the services I use that are unique except for the domain and prefix, receive email over them, and if really needed, reply as them and keep my actual mailbox hidden from them all.

Of course it won’t help that all my friends will uploads their bloody contact lists to Facebook, linkedin and others but it’s a start.

Any ideas on where I would start modifying the code to do this?

Is there a reason a “catch-all” email alias won’t work? Here’s what I have:

  1. An email address that I use for my personal things. (
  2. An email address that I use for things like list subscriptions, etc. (
  3. A catch-all alias that routes to

To my friends and family, I give out
To anything else, they get “”.
When the email comes in, the catch-all alias sends that mail to

The tricky bit comes when you need to do a reply, you’ll need to set your CLIENT up to set the “received” address as the reply-to in your replies. I never reply using my impersonal account, so I haven’t bothered to set this up, but most clients will allow it.

1 Like

I hadn’t thought about changing the clients setting for replying. I thinking of using the catch all to dump mail into a mailbox and then do the processing from their programmatically. I’ve written simple pop3 clients before and I assume mailbox creation can be done from a script, at least I hope. Hmm may try your setup as a starting point being that I then don’t have to write anything at all :grin:

You can definitely create mailboxes with a script, but then that’s that many more mailboxes you have to administer (each mailbox has to have a password, afterall…). With a catch-all alias, everything is just directing to one mailbox. Admittedly, it works much better for consumption only emails (newsletters, site registrations, etc.), but setting up the client to handle multiple senders is also pretty easy.

If you want to create users, the relevant bit as far as MIAB is concerned is just:

    curl -X POST -d "" -d "password=s3curE_pa5Sw0rD" --user

Hope that helps!