Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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
share|improve this question

1 Answer 1

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: http://bent.latency.net/smtpprox/.

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 at 22:11

Your Answer

 
discard

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.