Is there a way to generate a bounce programmatically? The only thing I found is "-N" flag in sendmail wrapper and bounce_template_file configuration parameter:

/usr/sbin/sendmail -N failure

But for some reason it generates a regular message. Not even using the bounce template.

Here's the scenario: postfix accepted a message from outside and pushed it to an external filter via SMTP. Basing on policy we decided to reject the message. Now we need to generate an NDR. How to do that with postfix?



You would simply create a new email and send it off to the sender.

One way to do this would be to divert it to a script - for example using the transport table to catch the email, and the master table to pipe the output to a script to generate the bounce response.

The entry in the master table might look something like

    unix    -   n   n   -   -   pipe flags=Rq
    user=nobody argv=/path/to/bounce.script ${sender} ${recipient}

Instead of sending sending the message to REJECT, you would send it to "bouncer". Not sure how you are rejecting it, so not sure how to tell it to go to bouncer instead. I guess you could use the transport table for this, or the header_checks table with the FILTER target.

A simple PHP script to send back the bounce message (untested) might look something along the following lines:

#! /usr/bin/php
      # Make sure phpmailer is installed !  (apt-get install phpmailer
      # or download from source and adjust path)
      include phpmailer/class.phpmailer.php



      $message="Bounce Message text here";
      $msg=new PHPMailer();
      $msg->Subject="Bounce Notification Subject Line";
      $msg->Body="Bounce Notification Message";
  • Thank you Dave, though I was hoping to deal without scripts. Postfix already has this functionality built-in: templates, right content/type, etc. Anyway thanks for your suggestion. – Sergey Romanovsky Mar 18 '16 at 19:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.