LOCALMAILFILTER(7)
π localmailfilter(7) β Local mail filtering π
okay bestie, buckle up, we're talking about localmailfilter(7), which is literally the way the Courier mail server decides whether it even wants your mail. no cap. it's giving gatekeeper energy and honestly? iconic. let's get into it π«Ά
β¨ SYNOPSIS β¨
like, here's the whole vibe in six little commands:
echo /usr/bin/maildrop >/etc/courier/maildropfilter
mkdir $HOME/.mailfilters
vi $HOME/.mailfilters/rcptfilter $HOME/.mailfilters/rcptfilter-ext
vi $HOME/.mailfilters/smtpfilter $HOME/.mailfilters/smtpfilter-ext
chmod 700 $HOME/.mailfilters
chmod 600 $HOME/.mailfilters/*
yeah that's it. that's the whole setup. slay π
πΈ DESCRIPTION πΈ
so the maildrop mail filter can be used by the Courier mail server as a mail filtering engine, rejecting unwanted mail on a per-recipient basis. per-recipient!! she's picky and we love that for her π
here's the tea though: the actual filtering interface Courier uses does not really require that maildrop be the engine. it's just that maildrop happens to have a compatible interface you can use right out of the box, no assembly required. the info below is enough for you to craft a homebrewed mail filter that takes maildrop's place. DIY queen behavior β¨
the local mail filter only works for addresses that correspond to local accounts. if the recipient is a remote address on another mail server? filtering is not used, not even a little. also, the local mail filter is disabled by default (she's shy π). to enable local mail filtering you'll need to initialize the /etc/courier/maildropfilter configuration file so it contains the pathname to your local mail filter.
local mail filtering happens in two distinct phases, and yes they are both main characters:
π¬ Recipient filters
when the Courier mail server receives an address naming a local mail recipient, the local mail recipient's mail filter is executed before the Courier mail server acknowledges the address. the local mail filter tells Courier whether to:
- A) accept the message unconditionally β the message is whitelisted, she said yes π
- B) reject the message unconditionally β the Courier mail server tells the other mail server that the recipient address is invalid, blocked, cancelled π
- C) accept this recipient, but run the content mail filter once the message's contents are available β the "we'll see" option, very mysterious of her
π₯ Content filters
after receiving the contents of the message, the mail filter is executed again for any recipients whose recipient filters used that third option. the content filter can now actually examine the contents of the message and indicate whether the message should be accepted or rejected. and listen β content filtering is not available for alias addresses. sad but true π
quick note bestie: mail filtering is executed as an integral part of receiving a message from a remote mail server. if the message is rejected, the Courier mail server refuses to accept the message for delivery. periodt.
the local mail filter will be invoked like this:
HOME=$HOME FILTER -D uid/gid -M filter
and this part matters: the local mail filter will NOT be invoked as root. so if it needs to access files in the recipient's account, it must be installed setuid to root (which is how maildrop is installed by default). noted π
uid/gid is the recipient account's system userid and group id, respectively. the recipient account's home directory gets placed in the HOME environment variable prior to running FILTER, and filter is set as follows:
rcptfilterβ the mail filter is invoked initially when the remote mail server specifies this address as a recipient.FILTERshould terminate with one of these exit codes:0β this sender is acceptable;99β this sender is acceptable, but I want to run the content filter for this the message; any other non-zero exit code β the sender is not acceptable, reject the message.smtpfilterβ ifFILTERterminates with exit code99,FILTERruns again with this parameter set to the wordsmtpfilter.FILTERwill be invoked once the message has been received from the remote mail server, but not yet acknowledged. ifFILTERterminates with a non-zero exit code, the message is rejected. ifFILTERterminated with the exit code of zero, the message is accepted.rcptfilter-ext,smtpfilter-extβ if the recipient created sub-addresses β seedot-courier(5)[1] β a dash followed by the subaddressextis appended to the name of the filter.rcptfilter-alias-extβ this is howFILTERgets invoked if the address is a locally defined mail alias (extis the alias name).
the rcptfilter invocation must terminate with a zero exit code when the message originates from a mailing list or any other source that should be considered as "whitelisted". here's why that's a whole thing: this filtering model does not fit very well with some mail transfer protocols, so unless trusted sources are explicitly declared to be whitelisted, there is a remote possibility that the recipient will be removed from a mailing list because of a poorly-written mail filter from some other recipient of the same message π¬. the 0 return exit code (which is the implied default if no mail filtering is installed) protects the recipient from being adversely affected, in any way, by anyone else's mail filter. she's protecting you fr fr π«Ά
the mail filters may print a diagnostic message before rejecting a message. that diagnostic message will be returned to the sending mail relay, where possible. so like, say it with your chest π
the mail filters inherit environment variables that describe the incoming mail. the following environment variables are provided by default:
SENDERβ the return address on the message.TCPREMOTEHOST,TCPREMOTEIPβ when the message is received via ESMTP, these variables specify the remote IP address and the corresponding hostname. Hostname is empty if the IP address does not have a reverse DNS record, or is set to"softdnserr"if there was a temporary failure while looking up this IP address.BLOCK2β the default the Courier mail server configuration sets this environment variable if the remote IP address is listed in an unsecured relay blacklist. see/etc/courier/esmtpdfor more information.
other environment variables may also be available. for mail received via ESMTP, environment variables are usually set in the /etc/courier/smtpaccess configuration file. iykyk β¨
π§ maildrop implementation
maildrop implements this mail filtering API as follows:
$HOME/.mailfiltersβ this directory contains the filtering recipes. this directory, and its contents, cannot have any group or world permissions. lock it down, bestie πsmtpfilter*,rcptfilter*β these mail filtering recipes directly correspond to the events defined in the previous section.maildrop's"import"statement can be used to gain access to the environment variables (these mail filters are executed inmaildrop's embedded mode). the mail filtering recipes can set theEXITCODEvariable appropriately before terminating, in order to accept or reject the message.
see maildrop(1)[2] for more information.
π Filtering mail to aliases
the /etc/courier/aliases configuration file is used to mail aliases, see makealiases(8)[3]. the system administrator may set aside a reserved local account that will be used to specify a local mail filter for messages addressed to aliases. the configuration file /etc/courier/aliasfilteracct specifies the home directory of the mail account that will be used to filter alias recipients.
for example, if /etc/courier/aliasfilteracct contains /home/admin, then the Courier mail server runs the mail filter as follows:
HOME=/home/admin FILTER -D uid/gid -M rcptfilter-alias-name
here, uid/gid is owner uid and gid of the specified directory. NOTE: name is a fully qualified address, and the local aliases listed in /etc/courier/aliases do not typically include the domain name. if [it] defines an alias called "system", for example, the -M option will probably be "system@example.com", if example.com is the contents of /etc/courier/me configuration file. honestly the domain thing trips everyone up, no shame π
unfortunately, currently it is not possible to specify content filters (a.k.a. smtpfilters) for aliases, only recipient filters. crying, throwing up, etc. π
π FILES π
/etc/courier/maildropfilterβ Local mail filtering engine./etc/courier/aliasfilteracctβ Account that is used to filter mail to aliases.
π SEE ALSO π
courierfilter(8)[4], maildrop(1)[2].
βοΈ AUTHOR βοΈ
Sam Varshavchik β Author
π NOTES π
dot-courier(5)β https://www.courier-mta.org/dot-courier.htmlmaildrop(1)β https://www.courier-mta.org/maildrop.htmlmakealiases(8)β https://www.courier-mta.org/makealiases.htmlcourierfilter(8)β https://www.courier-mta.org/courierfilter.html
and that's a wrap on localmailfilter(7), from the Courier Mail Server, dated 01/10/2026. go forth and filter responsibly, you absolute legend πβ¨ππ¦
mwah π
π¦ where this page comes from
- ubuntu stonking: courier-mta 2.0.6-1 Β· GPL-3+~with-OpenSSL-exception
- Copyright 1998 - 2009 S. Varshavchik. See COPYING for -->
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms