【问题标题】:Do not print stack trace on Postfix's mail delivery failure notification不要在 Postfix 的邮件传递失败通知上打印堆栈跟踪
【发布时间】:2019-07-30 15:43:38
【问题描述】:

当我们的服务未能发送电子邮件时,返回给发件人的拒绝通知包含失败代码的堆栈跟踪。有没有办法发送交货通知,而不会附加错误?

我们有一个 postfix 服务器,它在一个包罗万象的 python 脚本中处理传入的电子邮件。该脚本将电子邮件上传到我们的一项服务,并在失败时抛出异常。

这是我们使用的模板

failure_template = <<EOF
Charset: us-ascii
From: MAILER-DAEMON (Mail Delivery System)
Subject: Undelivered Mail Returned to Sender
Postmaster-Subject: Postmaster Copy: Undelivered Mail

This is the mail system at host $myhostname.

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
EOF

预期的结果将只是模板通知,没有 catch-all 脚本的轨迹。

【问题讨论】:

    标签: postfix-mta


    【解决方案1】:

    邮件服务器只是将 Python 程序在其标准错误中显示的任何内容包含在退回中。也许通过一个包装器调用脚本,它将标准错误保存到一个正常的地方(或者甚至丢弃它,如果你确定它从不包含任何有用的东西)。

    #!/bin/sh
    python3 /path/to/deliver.py 2>>/var/log/deliver.log
    

    您的邮件服务器显然需要对日志具有写入权限,并且您可能希望为文件设置定期日志轮换。

    可能更好的整体方法是让 Python 程序不崩溃。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-27
      • 2011-01-18
      • 1970-01-01
      • 2016-03-16
      相关资源
      最近更新 更多