Since release 6.4.0 OpenSmtpd has support for external filters.
It takes some time to understand its concept.
Here is a small showcase about it.
- Install OpenSMTPD
- Create a simple smtpd.conf
filter afilter proc-exec "/usr/bin/python3 /tmp/afilter/afilter.py"
listen on eth0 port smtp filter { afilter }
action "inbound" mbox
action "outbound" relay filter {afilter}
match from any for local action "inbound"
match from local for any action "outbound"
- Copy afilter.py and afilter_utils.py to the right location.
- Start smtpd:
smtpd -f smtpd.conf -d
- Test your SMTP server:
swaks -f [email protected] -t [email protected] -s localhost -ehlo home.local
- Watch your output:
- Request: OpenSmtpd -> Filter color is purple
- Response: OpenSmtpd <- Filter color is green 6See results complete log in /tmp/opensmtpd_afilter.log
See also: ./sample_log.txt
- Implement abstract methods like FilterSmtpIn->mail_from(ctx, address)
class ReportSmtpIn(IReportSmtpIn):
@staticmethod
def link_connect(ctx, rdns, fcrdns, src, dest):
# your implementation
pass
- Listen only for special reports / filters
hooks = [
ReportSmtpIn.link_connect, ...
]