1# Envelope sender / recipient rewriting23`replace_sender` and `replace_rcpt` modules replace SMTP envelope addresses4based on the mapping defined by the table module (maddy-tables(5)). It is possible5to specify 1:N mappings. This allows, for example, implementing mailing lists.67The address is normalized before lookup (Punycode in domain-part is decoded,8Unicode is normalized to NFC, the whole string is case-folded).910First, the whole address is looked up. If there is no replacement, local-part11of the address is looked up separately and is replaced in the address while12keeping the domain part intact. Replacements are not applied recursively, that13is, lookup is not repeated for the replacement.1415Recipients are not deduplicated after expansion, so message may be delivered16multiple times to a single recipient. However, used delivery target can apply17such deduplication (imapsql storage does it).1819Definition:2021```22replace_rcpt <table> [table arguments] {23 [extended table config]24}25replace_sender <table> [table arguments] {26 [extended table config]27}28```2930Use examples:3132```33modify {34 replace_rcpt file /etc/maddy/aliases35 replace_rcpt static {36 entry a@example.org b@example.org37 entry c@example.org c1@example.org c2@example.org38 }39 replace_rcpt regexp "(.+)@example.net" "$1@example.org"40 replace_rcpt regexp "(.+)@example.net" "$1@example.org" "$1@example.com"41}42```4344Possible contents of /etc/maddy/aliases in the example above:4546```47# Replace 'cat' with any domain to 'dog'.48# E.g. cat@example.net -> dog@example.net49cat: dog5051# Replace cat@example.org with cat@example.com.52# Takes priority over the previous line.53cat@example.org: cat@example.com5455# Using aliases in multiple lines56cat2: dog57cat2: mouse58cat2@example.org: cat@example.com59cat2@example.org: cat@example.net60# Comma-separated aliases in multiple lines61cat3: dog , mouse62cat3@example.org: cat@example.com , cat@example.net63```