using swift to detect bouncebacks

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

using swift to detect bouncebacks

Postby s.dot » Mon Dec 17, 2007 8:14 pm

In the past, I've had a server get blacklisted because I blindly sent out mail frequently to my entire member list, regardless if the email address was good or invalid or anything.

I'd like to set up some sort of thing when I batch mail to detect the emails that immediately get rejected and flag them in my database. Is this possible using only swift.. or perhaps a swift plugin?

If not, I can do it manually by setting the return path and checking the mailbox all the time, but It'd be nice to do it in the application.
"This place is old, it feels just like a beat up truck. I turn the engine but the engine doesn't turn. Smells of cheap wine and cigarettes, this place is always such a mess. Sometimes I think I'd like to watch it burn."
User avatar
s.dot
Tranquility In Moderation
 
Posts: 4654
Joined: Sun Feb 06, 2005 8:18 pm
Location: Indiana

Postby John Cartwright » Mon Dec 17, 2007 8:32 pm

scottay no like reading the documentation? :) Although I fail to see why you would get blacklisted for sending emails to non-existent addresses.

http://swiftmailer.org/wikidocs/v3/send ... recipients
Code: Select all
if ($toBe || $notToBe) echo 'That is the question'

ATTENTION: Please read the Forum Rules, and take the Forum Tour before posting!
User avatar
John Cartwright
Extreme Guru Moderator
 
Posts: 10581
Joined: Tue Dec 23, 2003 3:10 am
Location: Toronto

Postby s.dot » Mon Dec 17, 2007 8:59 pm

I was reading around in the tips for not being flagged as spam :)

Thanks for that link. Looks really useful.
"This place is old, it feels just like a beat up truck. I turn the engine but the engine doesn't turn. Smells of cheap wine and cigarettes, this place is always such a mess. Sometimes I think I'd like to watch it burn."
User avatar
s.dot
Tranquility In Moderation
 
Posts: 4654
Joined: Sun Feb 06, 2005 8:18 pm
Location: Indiana

Postby apexa » Tue Dec 18, 2007 8:52 am

This is tricky to do..something I'm looking into at the moment..that link above doesnt really apply because it only deals with invalid/malformed addresses that are rejected immediately by your local smtp server. The addresses you have to worry about are the ones that are sent out by your server but then bounced back by remote servers. I believe repeat sending to these bad addresses *can* get you blacklisted as it makes you look like a spammer (who will never bother cleaning their list).

So to really keep your list clean, you need to:
  • process getFailedRecipients() as linked to above - this returns all email addresses rejected by your local server because e.g. they aren't proper e-mail addresses.
  • set up the return path and a mailbox to catch bounces
  • process the bounces to determine which emails to mark as bad

The difficult part is the last bit - since just because you receive a bounce from an email address, it doesnt mean the address is bad. Some addresses may have intermittant problems, you'll get "out of office" autoresponders to that address too, there's many different types of bounces to recognise and finally not all bounces you get back follow a standard format!

It can be fairly simple to do the processing manually as you said, this just becomes difficult if you have a large volume which is when you need an automated system.

I found these two articles rather useful to summarise the issue of bounces:

http://www.clickz.com/showPage.html?page=3439641
http://www.clickz.com/showPage.html?page=3464041

I'm currently working on a way to automate solving this, as I'm not aware of an open-source solution to do it. Note that it can't be a plugin to Swift as most of the work has to be done at some point in the future after sending your mails - probably by a cron job scheduled to run automatically on a regular basis.

I'm considering using the library from http://www.boogietools.com/ (which requires paying for) - you feed this the raw text of an email and it tells you whether it's a bounce, what address it bounced from etc. This doesnt do all the work however as I still need to retreive the mails from the return-path mailbox and make the decision as to when to mark an address as bad.

I'm in the early stages, so if anyone has any experience or suggestions as to what to do, or knows of a pre-existing alternative, then please let us all know!

Cheers,
-- A
apexa
Forum Newbie
 
Posts: 8
Joined: Tue Dec 04, 2007 9:50 am

Postby s.dot » Wed Dec 19, 2007 1:12 am

I'm thinking the only way to do it is manually.

Won't be too bad to process if an administration form is built to flag a field in the database. Just type in the email address and submit. Of course this tool would have to check for duplicate emails being entered within a relatively short amount of time, and that the email exists in the mailing list.

A minor pain, but worthy if you want to keep your list "clean".
"This place is old, it feels just like a beat up truck. I turn the engine but the engine doesn't turn. Smells of cheap wine and cigarettes, this place is always such a mess. Sometimes I think I'd like to watch it burn."
User avatar
s.dot
Tranquility In Moderation
 
Posts: 4654
Joined: Sun Feb 06, 2005 8:18 pm
Location: Indiana

Postby apexa » Wed Dec 19, 2007 2:10 am

yup - a semi-automated system like that form that makes it as easy as pasting in each email address would be the most efficient way if you only have a few bad addresses.. you could even make a form that lets you paste a bunch of addresses into a textbox and process them all at once for you!

i'm working on a system that's sending out 10s of 000s of mails a week and have a mailbox full of 000s of bounces, autoresponders and other junk..so i've got to work out a way to do it like the big boys!
apexa
Forum Newbie
 
Posts: 8
Joined: Tue Dec 04, 2007 9:50 am

Postby s.dot » Wed Dec 19, 2007 2:21 am

Good luck with that. Do post your solution if you arrive at one. :)
"This place is old, it feels just like a beat up truck. I turn the engine but the engine doesn't turn. Smells of cheap wine and cigarettes, this place is always such a mess. Sometimes I think I'd like to watch it burn."
User avatar
s.dot
Tranquility In Moderation
 
Posts: 4654
Joined: Sun Feb 06, 2005 8:18 pm
Location: Indiana

Postby Kieran Huggins » Wed Dec 19, 2007 12:00 pm

Swift is about sending mail, which is certainly very cool, but it isn't a complete mailing list suite.

You could use PHP's IMAP functions to check a bounce mailbox, perform a regex match for "delivery failed" or whatever the cool kids are saying these days, then remove the original TO address from your list.
User avatar
Kieran Huggins
DevNet Master
 
Posts: 3635
Joined: Wed Dec 06, 2006 5:14 pm
Location: Toronto, Canada

Re: using swift to detect bouncebacks

Postby Flurrywinde » Tue Feb 05, 2008 4:33 am

Use the code found here: http://www.anti-spam-man.com/php_bouncehandler/v4/ . It's a class that, when fed a bounce e-mail, extracts information about the bounce, like the e-mail address in question and the nature of the bounce (i.e. transient, permanent, etc.).

What I did was take this code and make it into a PHP file that accepts input from stdin. Then, I pipe all incoming e-mail to the return-path address to this file, which automatically extracts the bounce information and puts it into a database.

I plan to write code that will process these database entries, either semi-automatically or automatically. If you beat me to it, hand it over! ;-) Even as is, however, having the bad e-mail addresses in a database makes things a lot easier.

Here's the meat of my file: (Pretty much the only thing I removed is the code for connecting to my database and my e-mail address.)

Syntax: [ Download ] [ Hide ]
require_once("bounce_driver.class.php");
 
// read e-mail from stdin
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
    $email .= fread($fd, 1024);
}
fclose($fd);
 
// Scan e-mail for bounce data
$bounceInfoArray = Bouncehandler::get_the_facts($email);
 
// If it's a bounce, record the recipient
// Otherwise, redirect the e-mail for user perusal
//
foreach($bounceInfoArray as $the){
    switch($the['action']){
        case 'failed':
        case 'autoreply':
        case 'transient':
            $bad_recipient = $the['recipient'];
            $bounce_action = $the['action'];
 
            $time = time();
            $sql = "INSERT INTO
            bounce(bad_recipient,bounce_action,time,email) VALUES('$bad_recipient','$bounce_action',$time,'"
.mysql_real_escape_string($email)."')";
            mysql_query($sql, $dbh);
            break;
        default:
            // Extract the head and body of the e-mail
            $bounce = BounceHandler::init_bouncehandler($email, 'string');
            list($head, $body) = preg_split("/\r\n\r\n/", $bounce, 2);
            $head_hash = BounceHandler::parse_head($head);     
            // Send e-mail in question to new recipient
            $mail_result = mail('your email address here', $head_hash['Subject'], "The following e-mail was processed by the bounce manager:\n\n".$email);
    }
}
 
Flurrywinde
Forum Newbie
 
Posts: 18
Joined: Mon Feb 04, 2008 4:30 pm


Return to Swift Mailer

Who is online

Users browsing this forum: No registered users and 1 guest