- 论坛徽章:
- 0
|
谢谢
的确可以这样做,用了transport,不用考虑是mta还是mda,最后都会relay过去
我参考了下oreilly_postfix_the_definitive_guide.chm,发现的确有点意思,感觉就是自动回复机制,不过有些postfix的原理还没理解透
(还有些问题:
1、应该可以直接用alias来调用pipe,但别名太多,比较麻烦
2、如果要用shell扫所有通过mta的邮件,再传回去,会不会邮件循环
3、想把它串联在mailscanner,因为我目前系统只做SMTP而已,目前这样做效率不太高
)
有几个地方想不明白,还在试验中
以下是目前的测试方法
[root@mail ~]# vi /etc/postfix/main.cf
transport_maps=hash:/etc/postfix/transport
inforeply_destination_recipient_limit=1
[root@mail ~]# vi /etc/postfix/transport
test@test.com inforeply
[root@mail ~]# postmap /etc/postfix/transport
[root@mail ~]# useradd autoresp
[root@mail ~]# vi /etc/postfix/master.cf
inforeply unix - n n - - pipe
flags= user=autoresp argv=/usr/local/bin/inforeply.pl ${sender}
[root@mail ~]# ll /usr/local/bin/inforeply.pl
[root@mail ~]# vi /usr/local/bin/inforeply.pl
#!/usr/bin/perl -w
#my $UID = 500;this number may change to autoresp's uid
#
# inforeply.pl - Automatic email reply.
#
# All messages are logged to your mail log. Check the
# log after executing the script to see the results.
#
# Set $UID to the uid of the process that runs the script.
# Check the entry in master.cf that calls this script. Use
# the uid of the account you assign to the user= attribute.
# If you want to test the script from the command line,
# set $UID to your own uid.
#
# Set $ENV_FROM to the envelope FROM address you want on
# outgoing replies. By default it's blank, which will
# use the NULL sender address <>. You can set it to an
# address to receive bounces, but make sure you don't set
# it to the same address that invokes the program, or
# you'll create a mail loop.
#
# Point $INFOFILE to a text file that contains the text of
# the outgoing reply. Include any headers you want in the
# message such as Subject: and From:. The To: header is
# set automatically based on the sender's address. Make
# sure you have an empty line between your headers and the
# body of the message.
#
# If necessary, change the path to sendmail in $MAILBIN.
#
# @MAILOPTS contains options to sendmail. Make changes if
# necessary. The default options should work in most
# situations.
#
# The calls to syslog require that your Perl installation
# converted the necessary header files. See h2ph in your
# Perl distribution.
#
require 5.004; # for setlogsock in Sys::Syslog module
use strict;
use Sys::Syslog qw( EFAULT setlogsock);
#
# Config options. Set these according to your needs.
#
my $UID = 500;
my $ENV_FROM = "";
my $INFOFILE = "/home/autoresp/inforeply.txt";
my $MAILBIN = "/usr/sbin/sendmail";
my @MAILOPTS = ("-oi", "-tr", "$ENV_FROM" ;
my $SELF = "inforeply.pl";
#
# end of config options
my $EX_TEMPFAIL = 75;
my $EX_UNAVAILABLE = 69;
my $EX_OK = 0;
my $sender;
my $euid = $>;
$SIG{PIPE} = \& ipeHandler;
$ENV{PATH} = "/bin:/usr/bin:/sbin:/usr/sbin";
setlogsock('unix');
openlog($SELF, 'ndelay,pid', 'user');
#
# Check our environment.
#
if ( $euid != $UID ) {
syslog('mail|err',"error: invalid uid: $> (expecting: $UID)" ;
exit($EX_TEMPFAIL);
}
if ( @ARGV != 1 ) {
syslog('mail|err',"error: invalid invocation (expecting 1 argument)" ;
exit($EX_TEMPFAIL);
} else {
$sender = $ARGV[0];
if ( $sender =~ /([\w\-.%]+\@[\w.-]+)/ ) { # scrub address
$sender = $1;
} else {
syslog('mail|err',"error: Illegal sender address" ;
exit($EX_UNAVAILABLE);
}
}
if (! -x $MAILBIN ) {
syslog('mail|err', "error: $MAILBIN not found or not executable" ;
exit($EX_TEMPFAIL);
}
if (! -f $INFOFILE ) {
syslog('mail|err', "error: $INFOFILE not found" ;
exit($EX_TEMPFAIL);
}
#
# Check sender exceptions.
#
if ($sender eq ""
|| $sender =~ /^owner-|-(request|owner)\@|^(mailer-daemon|postmaster)\@/i) {
exit($EX_OK);
}
#
# Check message contents for Precedence header.
#
while ( <STDIN> ) {
last if (/^$/);
exit($EX_OK) if (/^precedence:\s+(bulk|list|junk)/i);
}
#
# Open info file.
#
if (! open(INFO, "<$INFOFILE" ) {
syslog('mail|err',"error: can't open $INFOFILE: %m" ;
exit($EX_TEMPFAIL);
}
#
# Open pipe to mailer.
#
my $pid = open(MAIL, "|-" || exec("$MAILBIN", @MAILOPTS);
#
# Send reply.
#
print MAIL "To: $sender\n";
print MAIL while (<INFO> ;
if (! close(MAIL) ) {
syslog('mail|err',"error: failure invoking $MAILBIN: %m");
exit($EX_UNAVAILABLE);
}
close(INFO);
syslog('mail|info',"sent reply to $sender");
exit($EX_OK);
sub PipeHandler {
syslog('mail|err',"error: broken pipe to mailer");
}
[ 本帖最后由 sprilich 于 2007-4-5 18:00 编辑 ] |
|