I'd like to run a script that looks at each email that comes through the server, it looks like Postfix only supports one script being ran, and that's currently being filled using SpamAssassin:
smtp inet n - n - - smtpd
-o content_filter=spamassassin
And here is the SpamAssassin content filter definition:
spamassassin unix - n n - - pipe
user=debian-spamd argv=/usr/bin/spamc -s 1536000 -e
/usr/sbin/sendmail -oi -f ${sender} ${recipient}
So I'm thinking I should create a pipeline script that can be configured to run other scripts, the idea is I could do something like this in /etc/postfix/master.cf:
smtp inet n - n - - smtpd
-o content_filter=pipeline
...
pipeline unix - n n - - pipe
user=debian-pipeline argv=/usr/bin/pipeline.py
--script "/some/random/script/runs/before/spamc --arg val"
--script "user=debian-spamd /usr/bin/spamc -s 1536000"
--script "/some/random/script/runs/after/spamc --arg val"
--script "/usr/sbin/sendmail -oi -f ${sender} ${recipient}"
The /usr/sbin/sendmail -oi -f ${sender} ${recipient} could probably be built-in to pipeline script with an option to override it I guess, but the idea is that the pipeline script would be called, and then it would run through it's configured scripts, reading the email in from stdin and then passing the output of the previous script to the stdin of the next script until it finishes running all the scripts and calls /usr/sbin/sendmail -oi -f ${sender} ${recipient}
There would need to be a way to tell pipeline what user to use for each script. I don't know if the above would actually work, but I would like to start testing this out and figuring out a path forward to support this. For instance, I'm uncertain if the -argv can be configured with a script that takes even more flags since most examples I see don't have flags.
Stuff I had open while Researching
smtp-sink - smtp-sink listens on the named host (or address) and port. It takes SMTP messages from the network and throws them away. The purpose is to measure client performance, not protocol compliance.
To chain content_filters, the basic idea is to connect the output of
the first filter to the input of the next filter. ... Chaining simple content filters is generally done outside of
postfix. What you need to do is change the first filter to send it's output directly to the second filter rather than putting the mail back in postfix. The second filter then returns the mail to postfix using the sendmail(1) command.
I'd like to run a script that looks at each email that comes through the server, it looks like Postfix only supports one script being ran, and that's currently being filled using SpamAssassin:
And here is the SpamAssassin content filter definition:
So I'm thinking I should create a
pipeline
script that can be configured to run other scripts, the idea is I could do something like this in/etc/postfix/master.cf
:The
/usr/sbin/sendmail -oi -f ${sender} ${recipient}
could probably be built-in to pipeline script with an option to override it I guess, but the idea is that thepipeline
script would be called, and then it would run through it's configured scripts, reading the email in from stdin and then passing the output of the previous script to the stdin of the next script until it finishes running all the scripts and calls/usr/sbin/sendmail -oi -f ${sender} ${recipient}
There would need to be a way to tell
pipeline
what user to use for each script. I don't know if the above would actually work, but I would like to start testing this out and figuring out a path forward to support this. For instance, I'm uncertain if the-argv
can be configured with a script that takes even more flags since most examples I see don't have flags.Stuff I had open while Researching
smtp-sink - smtp-sink listens on the named host (or address) and port. It takes SMTP messages from the network and throws them away. The purpose is to measure client performance, not protocol compliance.
This was mentioned in Postfix: save every outgoing mail in files.
Postfix Architecture Overview
TRIGGERING A PHP SCRIPT WHEN YOUR POSTFIX SERVER RECEIVES A MAIL
chaining content_filters - This is basically what I want to do, a snippet:
How to configure multiple pipe-based content filters? - This discusses the problem of multiple filters in a pipeline but doesn't resolve it that I can see
Adding multiple content filters to an email server with postfix and dovecot Pigeonhole/Sieve - The first part of this post is basically what I want to do
How do I set up postfix to store e-mail in a file instead of relaying it? - only tangentially related
Search