Postfix After-Queue 内容过滤器完整示例

Postfix After-Queue 内容过滤器完整示例

我正在尝试简单内容过滤器示例:我按照这里提到的步骤进行操作http://www.postfix.org/FILTER_README.html#simple_filter

但在内容过滤器的第 24 行,可以是这样的简单 shell 脚本

您需要指定内容过滤器

我的问题是:

是否有可以使用的带有内容过滤器(第 24 行)的完整示例?

 1 #!/bin/sh
 2 
 3 # Simple shell-based filter. It is meant to be invoked as follows:
 4 #       /path/to/script -f sender recipients...
 5 
 6 # Localize these. The -G option does nothing before Postfix 2.3.
 7 INSPECT_DIR=/var/spool/filter
 8 SENDMAIL="/usr/sbin/sendmail -G -i" # NEVER NEVER NEVER use "-t" here.
 9 
10 # Exit codes from <sysexits.h>
11 EX_TEMPFAIL=75
12 EX_UNAVAILABLE=69
13 
14 # Clean up when done or when aborting.
15 trap "rm -f in.$$" 0 1 2 3 15
16 
17 # Start processing.
18 cd $INSPECT_DIR || {
19     echo $INSPECT_DIR does not exist; exit $EX_TEMPFAIL; }
20 
21 cat >in.$$ || { 
22     echo Cannot save mail to file; exit $EX_TEMPFAIL; }
23 
24 # Specify your content filter here.
25 # filter <in.$$ || {
26 #   echo Message content rejected; exit $EX_UNAVAILABLE; }**
27 
28 $SENDMAIL "$@" <in.$$
29 
30 exit $?

答案1

我使用自己的过滤器。我使用 Perl 脚本而不是 shell。

#!/usr/bin/perl
use 5.010;
use strict;
use warnings;

my $str = do { local $/; <STDIN> };
my $recipient   = $ARGV[0];
my $filename = '/etc/postfix/myfilters/data.txt';
open(my $fh, '>', $filename) or die "Could not open file '$filename' $!";
print $fh  $str;
close $fh;

=========================

使用execsendmail

exec(" SENDMAIL $toemail > $bodyfile ");

如果您的过滤器不匹配,则不执行任何操作,它将被隔离。

相关内容