2

I need to run all mail addressed to local domains (as defined in vmail_domains) through a simple after-queue content filter which then re-injects the processed emails back into Postfix via sendmail.

I have successfully created a perl filter based on the example of a simple after-queue content filter shown in the postfix FILTER_README doc:

smtp      inet  n       -       n       -       -       smtpd -o content_filter=statusFilter
statusFilter unix -     n       n       -       -       pipe user=mailFilter argv=/mydir/filter.pl ${sender} ${recipient}

Unfortunately, that filter only filters the mail arriving via the internet and misses all of the local deliveries such as Postfix bounce messages, and I especially need to process the bounce messages, regardless of how they arrived.

Is there some way for all email addressed to local Postfix domains be filtered with a simple after-queue filter, regardless of whether it arrived from a local source or a remote source, while never filtering any mail being sent to remote (internet) domains?

r.j.bumble
  • 45
  • 1
  • 6

1 Answers1

3

Unfortunately, that filter only filters the mail arriving vid the internet and misses all of the local deliveries such as Postfix bounce messages, messages from other local users and messages from local scripts via sendmail.

This is one of limitation from simple content filter. Quote from Postfix documentation

The first example is simple to set up, but has major limitations that will be addressed in a second example. Postfix receives unfiltered mail from the network with the smtpd(8) server, and delivers unfiltered mail to a content filter with the Postfix pipe(8) delivery agent. The content filter injects filtered mail back into Postfix with the Postfix sendmail(1) command, so that Postfix can deliver it to the final destination.

This means that mail submitted via the Postfix sendmail(1) command cannot be content filtered.

The solution is using advanced content filter. It uses SMTP to talk with postfix instead using pipe. Because your current script can't talk with SMTP, then you can use smtpprox as describe in the documentation

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/.

It written in perl too, but it was released over ten years ago. Also Jesse Norell forked it in github repository.


Is there some way for all email addressed to local Postfix domains be filtered with a simple after-queue filter, regardless of whether it arrived from a local source or a remote source, while never filtering any mail being sent to remote (internet) domains?

Postfix itself can't distinguished local/remote domains when doing content_filter. Content filter decision was done before cleanup daemon email routing One alternative is manually checks the domain on your perl script.

masegaloeh
  • 18,236
  • 10
  • 57
  • 106
  • Thank you for your kind and helpful answer. Somehow I just didn't realize the that the Postfix bounce messages were arriving via local sendmail. Your reply clarified it all. Thanks. – r.j.bumble Jan 22 '15 at 22:57