Replacement for Postfix's local(8) and virtual(8).
Configuration file is /etc/altpostlocal/altpostlocal.yaml
.
This is a YAML 1.1 file.
Please remind anchors and aliases because these are very useful.
Key | Type | Description |
---|---|---|
extensions |
String |
Optional. See Extensions section. |
rematch |
Mapping |
Optional. See REMatch section. |
aliases |
Mapping |
See Aliases section. |
default |
Action[] |
Delivery action when alias matching failed. |
rescue |
String |
Optional. Writable directory path. Save email to there when action returns error. If this setting does not exist, exit status 78 (EX_CONFIG = configuration error) is returned. |
rescue_json |
Boolean |
Optional. If ture, save email as JSON with dump format on fail. |
die_quietly |
Boolean |
Optional. If true, always exit 0 even if lost email. |
Extensions
value is a Onigmo's RegExp string.
When alias matching, Aliases function finds longest address key.
For example, destination address is foo+bar+baz@example.com
and Extensions
is +
; Aliases function see foo+bar+baz@example.com
first, foo+bar@example.com
next, and foo@exmaple.com
last.
Extensions
value is a RegExp string, the behavior of Extensions is shown in simple code as follows:
extensions = Regexp.new(config["extensions"])
username.rindex(extensions)
REMatch
is a mapping.
Key is a Onigmo's RegExp string, value is a replacement address.
REMatch is performed before normal matching and replaces the recipient address.
Caution: REMatch can potentially slow down script processing significantly.
The result of REMatch also affects the value of ${recipient}
in pipe
.
Aliases is a Mapping
.
address: Action[]
address
is email address includes domain like virtual(5). If domain is not included, matching is done by user name alone, regardless of domain.
For example, foo@example.com
matches foo@exmaple.com
or with extension like foo+bar@example.com
, and foo
matches foo@example.com
, foo@example.net
or foo
.
Aliases are matched using the String#downcase
method and must be lowercase.
If an alias containing a domain is not matched, the address is matched excluding the domain. For this reason, addresses such as abuse and mailer-daemon, which need to capture mail but do not need to be configured by domain, can be written easily by writing only aliases that do not include a domain.
Special alias domain @.
matches just user.
For exmaple, jrh@.
matches just only jrh
.
Aliases beginning with @
will be matched by domain regardless of user part. @example.com
matches to foo@example.com
, bar@example.com
or foo+bar@example.com
Domain matching is performed when user part is not matched.
Address matching is performed in the following steps.
- Match to entire address
- Match while shortening user part extensions
- Match by user part without domain
- Match while shortening user part extensions without domain
- Match by domain only (domain catch-all)
- Default action
If you want alias in aliases, please use YAML's anchor and aliases.
type: maildir
value: <dir>
junk: <bool>
Save on $dir/new
as a Maildir.
dir
should be absolute directory path.
If optional junk
is true, save mail tp $dir/.Junk/new
. It is maybe looks as junk mail from IMAP client software.
type: pipe
cmd: <command>,
args: [<arguments...>]
timeout: <int>
onerror: Action
Write pipe to cmd
with args
.
pipe
expands ${sender}
or ${receipient}
on args
.
If optional timeout
is set, raise error after int
seconds.
If optional onerror
os set, treat specified action when pipe raises exception or pipe returns non-zero status instead of global rescue action.
Hint: args
is useful for override alias.
type: dump
value: <dir>
Save on dir
with JSON format.
JSON data is
{
"sender": "sender_address",
"recipients": "recipient_addresses",
"mail": "mail_body"
}
Dumped JSON can be attempted to be redistributed using altpostlocal -j jsonfile.json
.
type: nothing
Do nothing.
This is useful if you simply want to destroy an e-mail.
type: nouser
Exit with status 67 immidiately.
Caution: This action ends script process.
type: forward
value: [<address...>]
Forward to address(es) with sendmail
command.
type: forward
value: [foo@example.com]
is same as
type: pipe
cmd: sendmail
args: [foo@example.com]
Add altpostlocal to master.cf
.
altpostlocal unix - n n - - pipe
flags=F user=email argv=/usr/local/bin/altpostlocal -f ${sender} -- ${recipient}
user and argv should be change according to your environment.
Set altpostlocal to local_transport
.
local_transport = altpostlocal
Set empty to local_recipient_maps
for never reject e-mail to the destination listed in mydestination.
local_recipient_maps =
List all destination domains in mydestination
.
mydestination = example.com, example.net, example.org, example.info
Note: Don't use virtual_mailbox_domains
.