James Bachini

Email Bounce Handling

Here’s some PHP code developed to handle bounced email responses. This will give each response a code to $resno and a category to $rescat. There are 4 categories:

  • Unknown – Hard bounce user or email address isn’t valid
  • Spam – Soft bounce, blocked by spam filters
  • Full – Soft bounce, user is out of resources or inbox is full
  • Block – Soft bounce, IP/Domain is being blocked for SMTP connections

if (false) {
} elseif (preg_match (“/user doesn’t have/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ‘2’;
} elseif (preg_match (“/reach does not exist/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ‘3’;
} elseif (preg_match (“/account has been disabled/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ‘4’;
} elseif (preg_match (“/likely unsolicited mail/i”,$body)) {
$rescat    = ‘spam’;
$resno     = ‘5’;
} elseif (preg_match (“/mailbox unavailable/i”,$body)) {
$rescat    = ‘full’;
$resno     = ‘6’;
} elseif (preg_match (“/Blocked for abuse/i”,$body)) {
$rescat    = ‘spam’;
$resno     = ‘7’;
} elseif (preg_match (“/5.2.1/i”,$body)) {
$rescat    = ‘spam’;
$resno     = ‘8’;
} elseif (preg_match (“/5.7.1/i”,$body)) {
$rescat    = ‘block’;
$resno     = ‘9’;
} elseif (preg_match (“/due to spam content/i”,$body)) {
$rescat    = ‘spam’;
$resno     = ’10’;
} elseif (preg_match (“/Host or domain name not found/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’11’;
} elseif (preg_match (“/550 Blocked/i”,$body)) {
$rescat    = ‘spam’;
$resno     = ’12’;
} elseif (preg_match (“/554 Denied/i”,$body)) {
$rescat    = ‘spam’;
$resno     = ’13’;
} elseif (preg_match (“/mailbox is full/i”,$body)) {
$rescat    = ‘full’;
$resno     = ’14’;
} elseif (preg_match (“/temporarily over quota/i”,$body)) {
$rescat    = ‘full’;
$resno     = ’15’;
} elseif (preg_match (“/unexpected name server reply/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’16’;
} elseif (preg_match (“/Recipient does not exist/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’17’;
} elseif (preg_match (“/not a valid user/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’18’;
} elseif (preg_match (“/5.1.0 Address rejected/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’19’;
} elseif (preg_match (“/550 Mailbox not found/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’20’;
} elseif (preg_match (“/disabled or discontinued/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’21’;
} elseif (preg_match (“/No such user/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’22’;
} elseif (preg_match (“/No account by that name/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’23’;
} elseif (preg_match (“/550 permanent failure/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’24’;
} elseif (preg_match (“/Account Inactive/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’25’;
} elseif (preg_match (“/5.2.2 Over quota/i”,$body)) {
$rescat    = ‘full’;
$resno     = ’26’;
} elseif (preg_match (“/quota exceeded/i”,$body)) {
$rescat    = ‘full’;
$resno     = ’27’;
} elseif (preg_match (“/User unknown/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’28’;
} elseif (preg_match (“/loops back to myself/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’29’;
} elseif (preg_match (“/Mail delivery limit exceeded/i”,$body)) {
$rescat    = ‘full’;
$resno     = ’30’;
} elseif (preg_match (“/att.net/blocks/i”,$body)) {
$rescat    = ‘spam’;
$resno     = ’31’;
} elseif (preg_match (“/Relaying denied/i”,$body)) {
$rescat    = ‘spam’;
$resno     = ’32’;
} elseif (preg_match (“/this server doesn’t handle mail/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’33’;
} elseif (preg_match (“/Unknown user/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’34’;
} elseif (preg_match (“/rejected as spam/i”,$body)) {
$rescat    = ‘spam’;
$resno     = ’35’;
} elseif (preg_match (“/550 Unrouteable/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’36’;
} elseif (preg_match (“/probability of spam/i”,$body)) {
$rescat    = ‘spam’;
$resno     = ’37’;
} elseif (preg_match (“/Recipient address rejected/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’38’;
} elseif (preg_match (“/Invalid recipient address/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’39’;
} elseif (preg_match (“/554 No relaying allowed/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’40’;
} elseif (preg_match (“/mailbox temporarily disabled/i”,$body)) {
$rescat    = ‘full’;
$resno     = ’41’;
} elseif (preg_match (“/550 no mailbox by that name/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’42’;
} elseif (preg_match (“/Spam-score too high/i”,$body)) {
$rescat    = ‘spam’;
$resno     = ’43’;
} elseif (preg_match (“/Invalid recipient/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’44’;
} elseif (preg_match (“/address does not exist/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’45’;
} elseif (preg_match (“/is over quota/i”,$body)) {
$rescat    = ‘full’;
$resno     = ’46’;
} elseif (preg_match (“/Recipient unknown/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’47’;
} elseif (preg_match (“/554 rejecting banned content/i”,$body)) {
$rescat    = ‘spam’;
$resno     = ’48’;
} elseif (preg_match (“/Bad destination host/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’49’;
} elseif (preg_match (“/account is unavailable/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’50’;
} elseif (preg_match (“/longer accepts mail/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’51’;
} elseif (preg_match (“/does not exist/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’52’;
} elseif (preg_match (“/is suspended/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’53’;
} elseif (preg_match (“/not currently being accepted for this mailbox/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’54’;
} elseif (preg_match (“/User address required/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’55’;
} elseif (preg_match (“/Relay access denied/i”,$body)) {
$rescat    = ‘unkown’;
$resno     = ’56’;
} elseif (preg_match (“/relay not permitted/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’57’;
} elseif (preg_match (“/mailbox is inactive/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’58’;
} elseif (preg_match (“/User not known/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’59’;
} elseif (preg_match (“/inactive user/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’60’;
} elseif (preg_match (“/501 Bad address/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’61’;
} elseif (preg_match (“/invalid mailbox/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’62’;
} elseif (preg_match (“/I couldn’t find any host named/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’63’;
} elseif (preg_match (“/User not found/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’64’;
} elseif (preg_match (“/find a mail exchanger or IP address/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’65’;
} elseif (preg_match (“/Not our Customer/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’66’;
} elseif (preg_match (“/recipient rejected/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’67’;
} elseif (preg_match (“/sender was rejected/i”,$body)) {
$rescat    = ‘spam’;
$resno     = ’68’;
} elseif (preg_match (“/this message has been in the queue too long/i”,$body)) {
$rescat    = ‘block’;
$resno     = ’69’;
} elseif (preg_match (“/blocked/i”,$body)) {
$rescat    = ‘spam’;
$resno     = ’94’;
} elseif (preg_match (“/rejected/i”,$body)) {
$rescat    = ‘spam’;
$resno     = ’95’;
} elseif (preg_match (“/spam/i”,$body)) {
$rescat    = ‘spam’;
$resno     = ’96’;
} elseif (preg_match (“/unknown/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’97’;
} elseif (preg_match (“/relay/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’98’;
} elseif (preg_match (“/exist/i”,$body)) {
$rescat    = ‘unknown’;
$resno     = ’99’;
}

From here you can handle each category in any way you see fit, i.e. removing all hard bounces from the email list.
i.e. if ($rescat == ‘unknown’) { dowhatever(); }


Get The Blockchain Sector Newsletter, binge the YouTube channel and connect with me on Twitter

The Blockchain Sector newsletter goes out a few times a month when there is breaking news or interesting developments to discuss. All the content I produce is free, if you’d like to help please share this content on social media.

Thank you.

James Bachini

Disclaimer: Not a financial advisor, not financial advice. The content I create is to document my journey and for educational and entertainment purposes only. It is not under any circumstances investment advice. I am not an investment or trading professional and am learning myself while still making plenty of mistakes along the way. Any code published is experimental and not production ready to be used for financial transactions. Do your own research and do not play with funds you do not want to lose.


Posted

in

by