Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bounce_notice_recipient = someone@nowhere.com
- error_notice_recipient = someone@nowhere.com
- someone: /dev/null
- <?php
- #parse_logs.php
- # load local file into array
- $val = file("mail.log");
- $pattern = '/status=bounced/';
- foreach ($val as &$value) {
- if (preg_match($pattern,$value)) {
- $a = split('[<>]', $value);
- //if you prefer you can also use: preg_match_all('/<(.*)>/', '$value', $matches);
- #can be helpful to print the following to the screen during tests
- # echo $a[1];
- // Make a MySQL Connection
- mysql_connect("localhost", "username", "password") or die(mysql_error());
- mysql_select_db("postfix_db") or die(mysql_error());
- // Insert a row of information into the table "example"
- mysql_query("INSERT INTO emails (emailaddress) VALUES('$a[1]') ")
- or die(mysql_error());
- #again, if you want to see while running manually from cli
- #echo "Data Inserted!";
- }
- #again, if you want to see while running manually from cli
- #echo "n";
- }
- ?>
- php parse.php > results.txt
- php parse_logs.php | /usr/sbin/sendmail someemailaddress@nowhere.com
- notify_classes = bounce, 2bounce, resource, software
- 2bounce_notice_recipient=bouncepipe@example.com
- bounce_notice_recipient=bouncepipe@example.com
- bouncepipe@example.com bouncepipe:
- bouncepipe unix - n n - - pipe
- flags=DRhu user=list argv=/etc/postfix/bouncepipe.pl
- #!/usr/bin/perl
- my $message = '';
- my $sender = '';
- my $recipient = '';
- foreach $line ( <STDIN> )
- {
- $message .= $line;
- chomp( $line );
- if ( $line =~ /Final-Recipient: /)
- {
- my $index = index($line, ';');
- $recipient = substr($line, $index+2);
- }
- if ( $line =~ /X-Postfix-Sender: /)
- {
- my $index = index($line, ';');
- $sender = substr($line, $index+2);
- }
- }
- # Do whatever you need to do with $sender and $recipient
Add Comment
Please, Sign In to add comment