Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?


content_filter = scan:localhost:10025


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/ 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=
        -o smtpd_authorized_xforward_hosts=
share|improve this question
up vote 1 down vote accepted

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.

  • As SMTP server, postfix will use SMTP to give email to script. So your script must handle SMTP transaction on your own. Spawn process doesn't do it to you, instead it will handle as inetd.
  • As SMTP client, your script will give email back to postfix localhost:10026 with SMTP transaction too.

Snippet from that page.

The second example is more complex, but can give better performance, and is less likely to bounce mail when the machine runs into some resource problem. This content filter receives unfiltered mail with SMTP on localhost port 10025, and sends filtered mail back into Postfix with SMTP on localhost port 10026.

For non-SMTP capable content filtering software, Bennett Todd's SMTP proxy implements a nice PERL/SMTP content filtering framework. See:

share|improve this answer
thanks for the info. I commented out the listener on port 10025 and wrote i quick python relay to listen on 10025 and to pass it on to 10026. works like a charm! – Omriko Jun 14 '14 at 22:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.