spamtrap

OpenSMTPD filter

Catch spam by using spam traps. If you have any dedicated traps sprinkled around or maybe some old e-mail addresses that are only used by spammers nowadays, you can use them to protect your other mailboxes.

Build

Go >= 1.22 is required.


git clone https://netsend.nl/opensmtpd-filter-spamtrap.git
cd opensmtpd-filter-spamtrap
go build -o filter-spamtrap

Install


install -m555 -gbin filter-spamtrap /usr/local/libexec/smtpd/
mkdir   -m750           /var/spamtrap
useradd              -d /var/spamtrap -s /sbin/nologin spamtrap
chown -R spamtrap:wheel /var/spamtrap
touch               /etc/mail/spamtraps
chmod 640           /etc/mail/spamtraps
chown root:spamtrap /etc/mail/spamtraps

smtpd.conf:


filter "spamtrap" proc-exec "filter-spamtrap" user spamtrap group spamtrap
listen on egress filter { spamtrap }

Usage

Spamtrap addresses should be added to /etc/mail/spamtraps, one per line. Example using two traps:


echo sp@mtrap.nl           >  /etc/mail/spamtraps
echo spamtrap2@example.com >> /etc/mail/spamtraps

Once everyting is set, restart smtpd.

Notes

Syntax

usage: filter-spamtrap [-trapfile file] [-expire duration] [-redirect addr]
[-spammers dir]
       filter-spamtrap -stats [-expire duration] [-spammers dir]

  -expire duration
        after how long a spammer should be unlisted (default 192h)
  -redirect string
        rewrite recipient of trapped mail instead of adding an "X-Spam" header
  -spammers string
        directory to save catched spammers in (default "/var/spamtrap")
  -stats
        print statistics about spammers and exit
  -trapfile string
        file containing one trap address per line (default "/etc/mail/spamtraps")

Code and repository

Browse the source code online or clone the repository:

$ git clone https://netsend.nl/opensmtpd-filter-spamtrap.git