use Mail::DeliveryStatus::BounceParser; use DBI; my $dbh = DBI->connect("DBI:CSV:") or die "Cannot connect: " . $DBI::errstr; my $in_file = "testcsv"; my $out_file = "bounce_report.csv"; print "WARNING...this program will write over your ",$out_file, " file in a few sec.\n"; sleep 3; open (REPORT, "+>$out_file") or die "Cant open report file, $!"; print REPORT "Arival_Date,Email,Final_Recipient,Action,Std_Reason,Reason,SMTP_Code,Status,Diag_Code,Reporting_MTA,Host,Raw\n"; my($query) = "SELECT * FROM $in_file"; my($sth) = $dbh->prepare($query) or die "Cannot prepare: " . $dbh->errstr(); $sth->execute() or die "Cannot execute: " . $sth->errstr(); my($body); $sth->bind_columns(undef, \$body); my $n=0; while ($sth->fetch) { my $bounce = eval { Mail::DeliveryStatus::BounceParser->new( $body ) }; print $report->get('email'); $n++; } $sth->finish(); $dbh->disconnect(); close REPORT; print "Processing complete. In = ", $n, " records\n";