Procmail:pipe道编程,否则返回错误发件人

我正在尝试使用procmail 将特定域的所有消息发送到RT (请求跟踪器)。 不过,这更多的是关于.procmailrc文件的问题。

这是我目前的.procmailrc文件:

#Preliminaries SHELL=/bin/sh #Use the Bourne shell (check your path!) MAILDIR=${HOME} #First check what your mail directory is! LOGFILE=${MAILDIR}/procmail.log LOG="--- Logging ${LOGFILE} for ${LOGNAME}, " VERBOSE=yes MAILDOMAIN='rt.mydomain.com' RT_MAILGATE="/opt/rt3/bin/rt-mailgate" RT_URL="http://rt.mydomain.com/" LOGABSTRACT=all ### Trying to process using the rt-mailgate script :0 { # the following line extracts the recipient from Received-headers. # Simply using the To: does not work, as tickets are often created # by sending a CC/BCC to RT TO=`formail -c -xReceived: |grep $MAILDOMAIN |sed -e 's/.*for *<*\(.*\)>* *;.*$/\1/'` QUEUE=`echo $TO| $HOME/get_queue.pl` ACTION=`echo $TO| $HOME/get_action.pl` :0 hbw |/usr/bin/perl $RT_MAILGATE --queue $QUEUE --action $ACTION --url $RT_URL } ### Upon failure, I want to send back an error message to the user, saying ### "Queue does not exist." I took this code from the procmailex manpage. :0 Wh: no-queue.lock { ## Reply if error * !^FROM_DAEMON * !^X-Loop: [email protected] | formail -rD 8192 no-queue.cache :0 ehc |(formail -rI"Precedence: junk" -A"X-Loop: [email protected]" ; \ echo "The Queue or Action was invalid."; echo "--" \ ) | $SENDMAIL -oi -t } 

你看到我的.procmailrc文件有问题吗? 如果队列存在,它就可以正常工作,但在那之后,它只是将邮件发送到/ var / mail / username。 我想扔掉电子邮件并返回错误消息。

我真的没有在一段时间使用procmail,所以我很抱歉如果这不立即工作。

首先,你的脚本中嵌套是造成问题,因为它几乎削减了一半的配方。 无论如何他们不是必要的,所以我把他们删除了。 我也简化了结构并设置了它,所以它永远不会落入本地邮箱。

 #Preliminaries SHELL=/bin/sh #Use the Bourne shell (check your path!) MAILDIR=${HOME} #First check what your mail directory is! LOGFILE=${MAILDIR}/procmail.log LOG="--- Logging ${LOGFILE} for ${LOGNAME}, " VERBOSE=yes MAILDOMAIN='\(help\|rt\)\.\(ncom\|networklubbock\)\.com' RT_MAILGATE="/opt/rt3/bin/rt-mailgate" RT_URL="http://rt.ncom.com/" LOGABSTRACT=all ### Trying to process using the rt-mailgate script # the following line extracts the recipient from Received-headers. # Simply using the To: does not work, as tickets are often created # by sending a CC/BCC to RT TO=`formail -c -xReceived: |grep $MAILDOMAIN |sed -e 's/.*for *<*\(.*\)>* *;.*$/\1/'` QUEUE=`echo $TO| $HOME/get_queue.pl` ACTION=`echo $TO| $HOME/get_action.pl` :0w |/usr/bin/perl $RT_MAILGATE --queue $QUEUE --action $ACTION --url $RT_URL # the formail command below looks at the message sender and basically # swallows the message if it's seen the sender before. The number # is the size of the cache file of seen addresses. A lock file is # used because multiple formail processes editing that cache will # corrupt it. :0w:no-queue.lock | formail -rD 8192 no-queue.cache ### Upon failure, I want to send back an error message to the user, saying ### "Queue does not exist." I took this code from the procmailex manpage. # Don't send if this was a bounce from a mailer, and don't send if this # message contains the header put there to indicate a loop. :0 * !^FROM_DAEMON * !^X-Loop: [email protected] |(formail -rI"Precedence: junk" -A"X-Loop: [email protected]" ; \ echo "The Queue or Action was invalid."; echo "--" \ ) | $SENDMAIL -oi -t # trash anything that falls all the way through. This should only ever # happen if the message was a bounce or if it was a loop. :0 /dev/null 

希望有所帮助。 如果您对任何部分有任何疑问,请发表评论,我会尽力解释。 或者搞清楚如果不行的话,我会怎么样。