|
1 | 1 | # Multiple domains configuration |
2 | 2 |
|
3 | | -## Separate account namespaces |
| 3 | +By default, maddy uses email addresses as account identifiers for both |
| 4 | +authentication and storage purposes. Therefore, account named `user@example.org` |
| 5 | +is completely independent from `user@example.com`. They must be created |
| 6 | +separately, may have different credentials and have separate IMAP mailboxes. |
4 | 7 |
|
5 | | -Given two domains, example.org and example.com. foo@example.org and |
6 | | -foo@example.com are different and completely independent accounts. |
| 8 | +This makes it extremely easy to setup maddy to manage multiple otherwise |
| 9 | +independent domains. |
7 | 10 |
|
8 | | -All changes needed to make it work is to make sure all domains are specified in |
9 | | -the `$(local_domains)` macro in the main configuration file. Note that you need |
10 | | -to pick one domain as a "primary" for use in auto-generated messages. |
| 11 | +Default configuration file contains two macros - `$(primary_domain)` and |
| 12 | +`$(local_domains)`. They are used to used in several places thorough the |
| 13 | +file to configure message routing, security checks, etc. |
| 14 | + |
| 15 | +In general, you should just add all domains you want maddy to manage to |
| 16 | +`$(local_domains)`, like this: |
11 | 17 | ``` |
12 | 18 | $(primary_domain) = example.org |
13 | 19 | $(local_domains) = $(primary_domain) example.com |
14 | 20 | ``` |
| 21 | +Note that you need to pick one domain as a "primary" for use in |
| 22 | +auto-generated messages. |
15 | 23 |
|
16 | | -The base configuration is done. You can create accounts using |
17 | | -both domains in the name, send and receive messages and so on. Do not forget |
18 | | -to configure corresponding SPF, DMARC and MTA-STS records as was |
19 | | -recommended in the [introduction tutorial](tutorials/setting-up.md). |
| 24 | +With that done, you can create accounts using both domains in the name, send |
| 25 | +and receive messages and so on. Do not forget to configure corresponding SPF, |
| 26 | +DMARC and MTA-STS records as was recommended in |
| 27 | +the [introduction tutorial](tutorials/setting-up.md). |
20 | 28 |
|
21 | | -## Single account namespace |
| 29 | +Also note that you do not really need a separate TLS certificate for each |
| 30 | +managed domain. You can have one hostname e.g. mail.example.org set as an MX |
| 31 | +record for mulitple domains. |
22 | 32 |
|
23 | | -You can configure maddy to only use local part of the email |
24 | | -as an account identifier instead of the complete email. |
| 33 | +**If you want multiple domains to share username namespace**, you should change |
| 34 | +several more options. |
25 | 35 |
|
26 | | -This needs two changes to default configuration: |
| 36 | +You can make "user@example.org" and "user@example.com" users share the same |
| 37 | +credentials of user "user" but have different IMAP mailboxes ("user@example.org" |
| 38 | +and "user@example.com" correspondingly). For that, it is enough to set `auth_map` |
| 39 | +globally to use `email_localpart` table: |
27 | 40 | ``` |
28 | | -storage.imapsql local_mailboxes { |
29 | | - ... |
30 | | - delivery_map email_localpart |
31 | | - auth_normalize precis_casefold |
32 | | -} |
| 41 | +auth_map email_localpart |
| 42 | +``` |
| 43 | +This way, when user logs in as "user@example.org", "user" will be passed |
| 44 | +to the authentication provider, but "user@example.org" will be passed to the |
| 45 | +storage backend. You should create accounts like this: |
| 46 | +``` |
| 47 | +maddy creds create user |
| 48 | +maddy imap-acct create user@example.org |
| 49 | +maddy imap-acct create user@example.com |
33 | 50 | ``` |
34 | 51 |
|
35 | | -This way, when authenticating as `foxcpp`, it will be mapped to |
36 | | -`foxcpp` storage account. E.g. you will need to run |
37 | | -`maddy imap-accts create foxcpp`, without the domain part. |
38 | | - |
39 | | -If you have existing accounts, you will need to rename them. |
40 | | - |
41 | | -Change to `auth_normalize` is necessary so that normalization function |
42 | | -will not attempt to parse authentication identity as a email. |
| 52 | +**If you want accounts to also share the same IMAP storage of account named |
| 53 | +"user"**, you can set `storage_map` in IMAP endpoint and `delivery_map` in |
| 54 | +storage backend to use `email_locapart`: |
| 55 | +``` |
| 56 | +straoge.imapsql local_mailboxes { |
| 57 | + ... |
| 58 | + delivery_map email_localpart # deliver "user@*" to "user" |
| 59 | +} |
| 60 | +imap tls://0.0.0.0:993 { |
| 61 | + ... |
| 62 | + storage &local_mailboxes |
| 63 | + ... |
| 64 | + storage_map email_localpart # "user@*" accesses "user" mailbox |
| 65 | +} |
| 66 | +``` |
43 | 67 |
|
44 | | -When a email is received, `delivery_map email_localpart` will strip |
45 | | -the domain part before looking up the account. That is, |
46 | | -`foxcpp@example.org` will be become just `foxcpp`. |
| 68 | +You also might want to make it possible to log in without |
| 69 | +specifying a domain at all. In this case, use `email_localpart_optional` for |
| 70 | +both `auth_map` and `storage_map`. |
47 | 71 |
|
48 | 72 | You also need to make `authorize_sender` check (used in `submission` endpoint) |
49 | 73 | accept non-email usernames: |
50 | 74 | ``` |
51 | 75 | authorize_sender { |
52 | 76 | ... |
53 | | - auth_normalize precis_casefold |
54 | | - user_to_email regexp "(.*)" "$1@$(primary_domain)" |
| 77 | + user_to_email chain { |
| 78 | + step email_localpart_optional # remove domain from username if present |
| 79 | + step email_with_domains $(local_domains) # expand username with all allowed domains |
| 80 | + } |
55 | 81 | } |
56 | 82 | ``` |
57 | | -Note that is would work only if clients use only one domain as sender (`$(primary_domain)`). |
58 | | -If you want to allow sending from all domains, you need to remove `authorize_sender` check |
59 | | -altogether since it is not currently supported. |
60 | 83 |
|
61 | | -After that you can create accounts without specifying the domain part: |
| 84 | +## TL;DR |
| 85 | + |
| 86 | +Your options: |
| 87 | + |
| 88 | +**"user@example.org" and "user@example.com" have distinct credentials and |
| 89 | +distinct mailboxes.** |
| 90 | + |
| 91 | +``` |
| 92 | +$(primary_domain) = example.org |
| 93 | +$(local_domains) = example.org example.com |
| 94 | +``` |
| 95 | + |
| 96 | +Create accounts as: |
| 97 | + |
| 98 | +```shell |
| 99 | +maddy creds create user@example.org |
| 100 | +maddy imap-acct create user@example.org |
| 101 | +maddy creds create user@example.com |
| 102 | +maddy imap-acct create user@example.com |
| 103 | +``` |
| 104 | + |
| 105 | +**"user@example.org" and "user@example.com" have same credentials but |
| 106 | +distinct mailboxes.** |
| 107 | + |
| 108 | +``` |
| 109 | +$(primary_domain) = example.org |
| 110 | +$(local_domains) = example.org example.com |
| 111 | +auth_map email_localpart |
| 112 | +``` |
| 113 | + |
| 114 | +Create accounts as: |
| 115 | +```shell |
| 116 | +maddy creds create user |
| 117 | +maddy imap-acct create user@example.org |
| 118 | +maddy imap-acct create user@example.com |
| 119 | +``` |
| 120 | + |
| 121 | +**"user@example.org", "user@example.com", "user" have same credentials and same |
| 122 | +mailboxes.** |
| 123 | + |
62 | 124 | ``` |
63 | | -maddy imap-acct create foxcpp |
64 | | -maddy creds create foxcpp |
| 125 | + $(primary_domain) = example.org |
| 126 | + $(local_domains) = example.org example.com |
| 127 | + auth_map email_localpart_optional # authenticating as "user@*" checks credentials for "user" |
| 128 | +
|
| 129 | + storage.imapsql local_mailboxes { |
| 130 | + ... |
| 131 | + delivery_map email_localpart_optional # deliver "user@*" to "user" mailbox |
| 132 | + } |
| 133 | +
|
| 134 | + imap tls://0.0.0.0:993 { |
| 135 | + ... |
| 136 | + storage_map email_localpart_optional # authenticating as "user@*" accesses "user" mailboxes |
| 137 | + } |
| 138 | +
|
| 139 | + submission tls://0.0.0.0:465 { |
| 140 | + check { |
| 141 | + authorize_sender { |
| 142 | + ... |
| 143 | + user_to_email chain { |
| 144 | + step email_localpart_optional # remove domain from username if present |
| 145 | + step email_with_domains $(local_domains) # expand username with all allowed domains |
| 146 | + } |
| 147 | + } |
| 148 | + } |
| 149 | + ... |
| 150 | + } |
65 | 151 | ``` |
66 | | -And authenticate using "foxcpp" in email clients. |
67 | 152 |
|
68 | | -Messages for any foxcpp@* address with a domain in `$(local_domains)` |
69 | | -will be delivered to that mailbox. |
| 153 | +Create accounts as: |
| 154 | +```shell |
| 155 | +maddy creds create user |
| 156 | +maddy imap-acct create user |
| 157 | +``` |
0 commit comments