I followed the instructions in the postfix website on how to setup a content filter, I got the simple example up and running fairly quick, but after long hours of struggle I couldnt get the advanced filter to work.
I setup everything like in the example, the smtp listens on port 25 for unfiltered messages, it has a filter set to pass on messages to port 10025 that calls the filter script, and another smtp listener for filtered messages on port 10026.
In the simple example the script is the final stop in the message flow, it gets the message via standard input does its work and reinjects it using sendmail.
In the advanced example I dont seem to get the message and cant seem to pass it along.
I did successfully manage to return a: '550 content rejected' response.
I guess my question is how does the script receive the mail body and how does it return it to the mail queue? and how do I get it all to work?
main.conf:
content_filter = scan:localhost:10025
master.conf:
scan unix - - n - 10 smtp
-o smtp_send_xforward_command=yes
-o disable_mime_output_conversion=yes
-o smtp_generic_maps=
localhost:10025 inet n n n - 10 spawn
user=filter argv=/home/omri/filter.sh localhost 10026
localhost:10026 inet n - n - 10 smtpd
-o content_filter=
-o receive_override_options=no_unknown_recipient_checks,no_header_body_checks,no_milters
-o smtpd_helo_restrictions=
-o smtpd_client_restrictions=
-o smtpd_sender_restrictions=
# Postfix 2.10 and later: specify empty smtpd_relay_restrictions.
-o smtpd_relay_restrictions=
-o smtpd_recipient_restrictions=permit_mynetworks,reject
-o mynetworks=127.0.0.0/8
-o smtpd_authorized_xforward_hosts=127.0.0.0/8
Best Answer
In the section Simple content filter example, you can use pipe (e.g. stdin) to receive the mail body. In advanced ones, your script must capable to act as both SMTP server and SMTP client.
Snippet from that page.