Multiple domains configuration

Separate account namespaces

Given two domains, example.org and example.com. foo@example.org and foo@example.com are different and completely independent accounts.

All changes needed to make it work is to make sure all domains are specified in the $(local_domains) macro in the main configuration file. Note that you need to pick one domain as a "primary" for use in auto-generated messages.

$(primary_domain) = example.org
$(local_domains) = $(primary_domain) example.com

The base configuration is done. You can create accounts using maddyctl using both domains in the name, send and receive messages and so on. Do not forget to configure corresponding SPF, DMARC and MTA-STS records as was recommended in the introduction tutorial.

Single account namespace

Lets say you want to handle messages for domains example.org and example.com and make that foo@example.org and foo@example.com are the same accounts. Sadly, this case is not very well-supported by maddy, but it still can be implemented.

You already should have the primary domain set for autogenerated messages and so on. The idea is to redirect all messages from non-primary domains to the primary one.

For each handled domain, the following line should be added to the modify block that gets applied for local recipients:

replace_rcpt regexp /(.+)@example.com/ $1@$(primary_domain)

It does regexp replacement, turning anything@example.com into anything@$(primary_domain) where $(primary_domain) in our case is example.org.

E.g.

$(primary_domain) = example.org

# Probably somewhere in local_routing
modify {
    replace_rcpt regexp /(.+)@example.net/ $1@$(primary_domain)
    replace_rcpt regexp /(.+)@example.com/ $1@$(primary_domain)
}

With that configuration, all messages for foo@example.net and foo@example.com will end up in the foo@example.org mailbox.

Note, however, no account credentials aliasing is done. Users should always use the account name with the primary domain to access IMAP mailboxes.

Note 1: All domains should still be listed in the $(local_domains) macro.