AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 104779
Accepted
bradlis7
bradlis7
Asked: 2010-01-21 12:49:24 +0800 CST2010-01-21 12:49:24 +0800 CST 2010-01-21 12:49:24 +0800 CST

Procmail:管道到程序,否则返回错误给发件人

  • 772

我正在尝试使用 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 h b w 
|/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
  • 1 1 个回答
  • 2855 Views

1 个回答

  • Voted
  1. Best Answer
    Jeff Snider
    2010-01-21T18:47:02+08:002010-01-21T18:47:02+08:00

    老实说,我有一段时间没有使用 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
    

    希望有帮助。如果您对其中的任何部分有疑问,请发表评论,我会尽力解释。或者弄清楚如果它不起作用,我是如何搞砸的。

    • 2

相关问题

  • 使用 spamassassin 作为网络论坛的外部过滤器

  • 使用 sendmail 的服务器上的垃圾邮件每日报告

  • 请给我一个反垃圾邮件措施配方

  • 有没有办法过滤远程 IMAP 帐户中的邮件?

  • 什么是允许POP邮箱用户打开和关闭Vaction AutoReply的快速且易于理解的PROCMAIL方式

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    从 IP 地址解析主机名

    • 8 个回答
  • Marko Smith

    如何按大小对 du -h 输出进行排序

    • 30 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    MikeN 在 Nginx 中,如何在维护子域的同时将所有 http 请求重写为 https? 2009-09-22 06:04:43 +0800 CST
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    0x89 bash中的双方括号和单方括号有什么区别? 2009-08-10 13:11:51 +0800 CST
  • Martin Hope
    Kyle Brandt IPv4 子网如何工作? 2009-08-05 06:05:31 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve