This plugin allows the configuration of aliases that perform an action or change the RCPT address. Aliases are specified in a JSON formatted config file, and must have an action. Syntax errors found in the JSON config will stop the server.
IMPORTANT: this plugin must appear in config/plugins
before other plugins that run on hook_rcpt
WARNING: DO NOT USE THIS PLUGIN WITH queue/smtp_proxy.
JSON formatted config file that contains keys to match against RCPT addresses, and values that are objects with an "action" : "" property. Example:
{ "test1": { "action": "drop" } }
In the above example the "test1" alias will drop any message that matches test1, test1-, or test1+ (wildcard '-' or '+', see below). Actions may have 0 or more options listed like so:
{ "test3": { "action": "alias", "to": "test3-works" } }
In the above example the "test3" alias has an action of "alias" and a mandatory "to" field. If "to" were missing the alias would fail and an error would be emitted.
Aliases of 'user', '@host' and 'user@host' possible:
{ "demo" : { "action" : "drop" } }
or
{ "@example.com" : { "action" : "drop" } }
or
{ "[email protected]" : { "action" : "drop" } }
Aliases may be expanded to multiple recipients:
{
"[email protected]": {
"action": "alias",
"to": ["[email protected]", "[email protected]"]
}
}
This plugin supports wildcard matching of aliases against the right most string of a RCPT address. The characters '-' and '+' are commonly used for subaddressing and this plugin can alias the "user" part of the address.
If the address were [email protected] (or [email protected]), the below alias would match:
{ "test2": { "action": "drop" } }
Larger and more specific aliases match first when using wildcard '-' notation. If the above RCPT was evaluated with this alias config, it would alias:
{
"test2": { "action": "drop" },
"test2-testing": { "action": "alias", "to": "[email protected]" }
}
It also allows you to route all emails to a certain domain:
{
"*": { "action": "alias", "to": "[email protected]" }
}
Alias chaining is not supported. As a side-effect, we enjoy protections against alias circuits.
- optional one line formatting
Any valid JSON will due. Please consider keeping each alias on its own line so that others that wish to grep the aliases file have an easier time finding the full configuration for an alias.
- nondeterministic duplicate matches
This plugin was written with speed in mind. That means every lookup hashes into the alias file for its match. While the act of doing so is fast, it does mean that any duplicate alias entries will match nondeterministically. That is, we cannot predict what will happen here:
{
"coinflip": { "action": "alias", "to": "[email protected]" },
"coinflip": { "action": "alias", "to": "[email protected]" }
}
Due to node.js implementation, one result will likely always be chosen over the other, so this is not exactly a coinflip. We simply cannot say what the language implementation will do and it could change.
The following is a list of supported actions and their options.
-
drop
Drops a message while pretending everything was okay to the sender. This acts like an alias to /dev/null.
-
alias
Maps the alias key to the address specified in the "to" option. A note about matching in addition to the note about wildcard '-' above. When we match an alias, we store the hostname of the match for a shortcut substitution syntax later.
- to (required)
This option is the full address, or local part at matched hostname that the RCPT address will be re-written to. For an example of an alias to a full address consider the following:
{ "test5": { "action": "alias", "to": "[email protected]" } }
This maps RCPT matches for "test5" to "[email protected]". This would map "[email protected]" to "[email protected]" every time. Compare this notation with its shortcut counterpart, best used when the "to" address is at the same domain as the match:
{ "test4": { "action": "alias", "to": "test4" } }
This notation is more compact. Mail to "[email protected]" will map to "[email protected]". This notation enables lots of aliases on a single domain to map to other local parts at the same domain.
{
"test1": { "action": "drop" },
"test2": { "action": "drop" },
"test3": { "action": "alias", "to": "test3-works" },
"test4": { "action": "alias", "to": "test4" },
"test5": { "action": "alias", "to": "[email protected]" },
"test6": { "action": "alias", "to": "[email protected]" }
}