Loading ...
Sorry, an error occurred while loading the content.

Re: example showing how to track bad/bounce emails

Expand Messages
  • marshall
    Hmm; Thanks for your feedback, Wietse! I m definitely new to mail serving and not an administrator. Would it be at all advisable to just scan the maillog file
    Message 1 of 5 , Mar 31, 2011
    • 0 Attachment
      Hmm;

      Thanks for your feedback, Wietse!

      I'm definitely new to mail serving and not an administrator.

      Would it be at all advisable to just scan the maillog file periodically for 'status=bounce' lines and parse out the 'to<...>' email address?

      It seems that'd give a pretty reasonable list of bounced emails. I don't need to be 100% accurate, just reasonably comprehensive.

      Marshall


      From: Wietse Venema <wietse@...>
      To: Postfix users <postfix-users@...>
      Sent: Thu, March 31, 2011 12:56:14 PM
      Subject: Re: example showing how to track bad/bounce emails

      marshall:
      > Hello;
      >
      > I've been searching around for a while, but I've not found any documentation or
      > examples that show how you can configure Postfix to log bad/bounce/failed emails
      > to MySQL or how to read a log file and parse the bad/bounce/failed emails out of
      > it.
      >
      > The application I'm working on needs to detect emails that bounce
      > and ideally remove them from the database. If Postfix can insert
      > the bounced emails into a db table (or a log file that just contains
      > the bad email addres, one per line), that would make it pretty
      > easy to run a cron job to remove these bad emails from the
      > application's user database.

      Postfix delivers mail; it does not parse bounce messages.

      You could use the documented Postfix hooks to deliver the returned
      mail to a command that parses out the failed recipient.

      - "|command" in local alias or .forward file:
        http://www.postfix.org/local.8.html.
        http://www.postfix.org/aliases.5.html.

      - Pipe-to-command daemon; this requires a per-user transprort map entry.
        http://www.postfix.org/pipe.8.html
        http://www.postfix.org/transport.5.html

      Bounce message parsing is not trivial because a lot of systems use
      a non-standard notification format.  Using VERP solves some but
      not all of these problems (some mail systems ignore the envelope
      sender address).  http://www.postfix.org/VERP_README.html

          Wietse
    • Wietse Venema
      ... [examples deleted] ... Sorry, email is not an end-to-end protocol like HTTP. It is a store and forward protocol where mail travels over multiple SMTP
      Message 2 of 5 , Mar 31, 2011
      • 0 Attachment
        marshall:
        > If Postfix can insert the bounced emails into a db table (or a
        > log file that just contains the bad email addres, one per line),
        > that would make it pretty easy to run a cron job to remove these
        > bad emails from the application's user database.

        Wietse:
        > You could use the documented Postfix hooks to deliver the returned
        > mail to a command that parses out the failed recipient.
        [examples deleted]

        marshall:
        > Would it be at all advisable to just scan the maillog file periodically for
        > 'status=bounce' lines and parse out the 'to<...>' email address?

        Sorry, email is not an end-to-end protocol like HTTP. It is a store
        and forward protocol where mail travels over multiple SMTP sessions.

        Logfile parsing gives you only information about the first-hop mail
        delivery attempt. It does not give information about errors AFTER
        the first hop.

        Wietse
      • Andrew Beverley
        ... I wouldn t bother trying to parse the mail log, as Wietse has already implied. ... I do this, along with... ... ...this, and It Works For Me (TM). You ll
        Message 3 of 5 , Apr 3, 2011
        • 0 Attachment
          On Thu, 2011-03-31 at 12:56 -0400, Wietse Venema wrote:
          > marshall:
          > > Hello;
          > >
          > > I've been searching around for a while, but I've not found any documentation or
          > > examples that show how you can configure Postfix to log bad/bounce/failed emails
          > > to MySQL or how to read a log file and parse the bad/bounce/failed emails out of
          > > it.

          I wouldn't bother trying to parse the mail log, as Wietse has already
          implied.

          > >
          > > The application I'm working on needs to detect emails that bounce
          > > and ideally remove them from the database. If Postfix can insert
          > > the bounced emails into a db table (or a log file that just contains
          > > the bad email addres, one per line), that would make it pretty
          > > easy to run a cron job to remove these bad emails from the
          > > application's user database.
          >
          > Postfix delivers mail; it does not parse bounce messages.
          >
          > You could use the documented Postfix hooks to deliver the returned
          > mail to a command that parses out the failed recipient.
          >
          > - "|command" in local alias or .forward file:
          > http://www.postfix.org/local.8.html.
          > http://www.postfix.org/aliases.5.html.

          I do this, along with...

          > Bounce message parsing is not trivial because a lot of systems use
          > a non-standard notification format. Using VERP solves some but
          > not all of these problems (some mail systems ignore the envelope
          > sender address). http://www.postfix.org/VERP_README.html

          ...this, and It Works For Me (TM).

          You'll need to make sure that the sender address is something that can
          be recognised as a bounced email (I use owner-list@... for some
          mailing lists, which are then VERP encoded by Postfix).

          You'll then need an alias regular expression to pull out the email
          address and send to your script.

          I personally use a mysql aliases table, with the PREG_CAPTURE feature
          from the lib_mysqludf_preg library to pass the bounces to my bounce
          script. However, in your case, you'll probably just need to set up a
          regular expression aliases file to look for bounced email addresses.
          From the above example, something like:

          /^owner-(.*)$/ "|/path/to/script"

          Or, if you're using virtual domains, then I don't think you can pipe
          straight to a script, so you'll have to send to an alias (which should
          then forward to the script):

          /^owner-(.*)@domain$/ "alias"

          You'll then need to do something like this in a Perl script. Depending
          how your script is being called depends whether to use "x-original-to"
          or just "to", but I don't see any harm looking for both.

          while (<STDIN>) {
          if (/^x-original-to: <?\"?owner-([^+]*)\+(.*)\@([^>]*)/i) {
          $list = $1;
          $recipient = $2;
          $domain = $3;
          chomp($domain);
          } elsif (/^to: <?\"?owner-([^+]*)\+(.*)\@([^>]*)/i) {
          $list = $1;
          $recipient = $2;
          $domain = $3;
          chomp($domain);
          }
          }

          In this case, the bouncing email address is stored in $recipient, and
          the original owner-listname@domain email address is stored in $list and
          $domain (you may not need this bit).

          None of the above is tested, but hopefully it should give you something
          to work from.

          Andy
        Your message has been successfully submitted and would be delivered to recipients shortly.