来自脚本的Postfix退信消息错误信息

0 投票
1 回答
1180 浏览
提问于 2025-04-18 03:15

我想在Postfix中创建一个退信消息,这个消息能显示我过滤脚本中的错误信息。我发现如果我从脚本中返回一个错误代码,比如1,我会看到所有打印到标准输出的数据,但同时也会看到关于脚本文件的信息。例如:

This is the mail system at host mail.somesys.pl.

I'm sorry to have to inform you that your message could not be delivered to one or more recipients. It's attached below.

For further assistance, please send mail to postmaster.

If you do so, please include this problem report. You can delete your own text from the attached returned message.

                   The mail system

<user01@mail.somesys.pl>: Command died with status 1:
    "/opt/SmtpReceiver/SmtpReceiverHandler.py". Command output: NO FILES OR BAD
    CREDENTIALS

而我只想看到类似这样的内容:

...
                   The mail system

NO FILES OR BAD CREDENTIALS

这是我的Postfix master.cf配置:

smtp      inet  n       -       n       -       -       smtpd
        -o content_filter=myhook:dummy
...
myhook unix - n n - - pipe
  flags=F user=user01 argv=/opt/SmtpReceiver/SmtpReceiverHandler.py ${sender} ${size} ${recipient}

还有我的Python脚本:

if __name__=='__main__':

    try:
        app = SmtpReceiverHandler();
        app.run();
    except Exception, e:
        print e;
        sys.exit(1);

1 个回答

1

你可以在你的 main.cf 文件中指定 bouce_template_file

#/etc/postfix/main.cf
bounce_template_file = /etc/postfix/bounce.cf

#/etc/postfix/bounce.cf
failure_template = <<EOF
Charset: us-ascii
From: MAILER-DAEMON (Mail Delivery System)
Subject: Undelivered Mail Returned to Sender
Postmaster-Subject: Postmaster Copy: Undelivered Mail

    The mail system
EOF

参考资料:Postfix 文档

撰写回答