0

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?

Thanks!

1 Answer 1

1

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

bouncer
    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
<?php
      # Make sure phpmailer is installed !  (apt-get install phpmailer
      # or download from source and adjust path)
      include phpmailer/class.phpmailer.php

      $from=$argv[1];
      $to=$argv[2];

      $tz=date_default_timezone_get();
      date_default_timezone_set($tz);

      $message="Bounce Message text here";
      $msg=new PHPMailer();
      $msg->From=$to;
      $msg->FromName=$from;
      $msg->Subject="Bounce Notification Subject Line";
      $msg->Body="Bounce Notification Message";
      $msg->AddAddresses($from);
      $msg->send();
  ?>
1
  • 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. Mar 18, 2016 at 19:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .