Question

I want to create bounce message in postfix that will show error info from my filter script. I found out that if I return error code from script like 1 I will see all data printed to standard output but I will also see info about script file. For example:

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

And I want to have only something like that:

...
                   The mail system

NO FILES OR BAD CREDENTIALS

My postfix master.cf config:

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}

And python script:

if __name__=='__main__':

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

Solution

You can specify the bouce_template_file in your main.cf

#/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

Ref: Postfix docs

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top