PDA

View Full Version : Detecting Bounced Email


TalkVirginia
03-14-2010, 11:42 AM
I'm working on an addon and one of the features is that I'm trying to detect and trap bounced emails. I found a tutorial that walks through setting this up at the following page:

http://forums.theplanet.com/lofiversion/index.php/t89873.html

I'd like to run the following script on my shared host, but I'm not sure what vBulletin scripts I would need to include to allow me to add information from the bounced emails into my vbulletin database log table. Any suggestions?



#!/usr/local/bin/php -q
<?php

// Reading in the email
$fd = fopen("php://stdin", "r");
while (!feof($fd)) {
$email .= fread($fd, 1024);
}
fclose($fd);

// Parsing the email
$lines = explode("\n", $email);
$stillheaders=true;
for ($i=0; $i < count($lines); $i++) {
if ($stillheaders) {
// this is a header
$headers .= $lines[$i]."\n";

// look out for special headers
if (preg_match("/^Subject: (.*)/", $lines[$i], $matches)) {
$subject = $matches[1];
}
if (preg_match("/^From: (.*)/", $lines[$i], $matches)) {
$from = $matches[1];
}
if (preg_match("/^To: (.*)/", $lines[$i], $matches)) {
$to = $matches[1];
}
} else {
// not a header, but message
break;
// Optionally you can read out the message also, instead of the break:
//$message .= $lines[$i]."\n";
}

if (trim($lines[$i])=="") {
// empty line, header section has ended
$stillheaders = false;
}
}

list($part1,$dum1) = explode("-bounce@yoursite.com", trim($to) );
list($dum2,$user) = explode("user-", $part1);
//
// $user now contains the user id "12345" in the example
//
// Here you put in your custom code
// like open up your database connection and
// mark the user as invalid email address,
// so you don's send to him again.

return true;
?>

Biker_GA
03-18-2010, 03:14 AM
Funny thing. This very subject was brought up to me today and I've been doing a lot of reading regarding bounced email and backscatter spam.

The issue you're going to find is the scripts detailed in the link you provided need to be run as root. As you're on a shared server, it's highly unlikely that you have root access to the server itself. There have been numerous changes to exim over the past couple of years as well, and that script may very well be outdated since it was originally written in '08.

I'm still looking into this issue and it's a thorny one indeed. exim needs to be set to where it checks at SMTP, not when it's already accepted the email and is deciding where to route it. It's much easier to set this in the exim configuration files, and your host should have already done this. In my case, the host doesn't do squat for dedicated servers, so I'm having to figure this all out on my own. **banging head on desk**