I need to do some bounced mail processing using PHP. Going through the e-mails is no problem, but investing the resources in writing our own library to parse the bounced e-mails is very undesirable.
There are 3 PHP solutions that I've found that are supposed to be for processing bounced mail, but they are all way out of date and no longer maintained, from what I can see. (PHPList, PHPMailer-BMH, Bounce Handler @ PHPClasses.org)
Does anyone know of an up-to-date set of rules for processing bounced e-mails? I don't necessarily need any handling logic, even just an up-to-date ruleset would be satisfactory.
Thanks for any assistance.
Here's how I did it once before. It can capture at least over 70% of the bounce mails consistantly.
In the emails being sent out, put in a custom header (like "x-email-check-id") to have a unique identifer for each email being sent (maybe create a GUID and store that in the database for each email)
On the server end, write a cron job to periodically download emails from the bounce address, and look for this header in the reply message. That way, you can match the bounce mail with the email sent out. This way, you can establish that this email is bounced from your sending and is not a spam email.
After that, search the email content for specific keywords to determine the reason for bounce. This list of keywords should be updated often as newer email servers return different text. But here is the list that I used.
Bounce handling is non-trivial as you need to deal with a lot of different servers and responses. This includes those servers that are misconfigured and bounces because your email/host/IP has been blacklisted / spam-scored. And there are tons of bounces because of "out of office" auto-replies.
A simple solution I know is to put own headers into the message that identify the receiver address and the concrete sending (a token). When it bounces, the bounce can be verified based upon this.
Another solution is to encode additional information into the sender address and parse it accordingly for bounces. For this you need to know about how email works, which generally is useful if you need with bounces.
There is some great answer here on SO (but I haven't found it for this answer) that goes into many details on the topic. If I find it, I'll add it.
The general point is, that I don't know about many PHP based tools to deal with bounces, I know PHPList (PHP components for mailinglist handling) has something in their repository:
Edit: The related question with the very informative answer is:
Edit: It's not much, just some links:
There is RFC3834 - Recommendations for Automatic Responses to Electronic Mail which go updated by RFC5436 Sieve Notification Mechanism: mailto.
Bouncing is also discussed in part in RFC5321 Simple Mail Transfer Protocol, which clearly gives a reason that an MTA must report back if a message can not be delivered.
The main problem is that the bounce-address (the sender) can not be verified in SMTP, so sending a bounce message bears the problem that it probably goes to a wrong person (Backscatter Spam).
A relyable mailer therefore not only checks for bounces but does more with SMTP to gain a certain level of quality, see:
The whole Wikipedia page of the Non delivery report might be interesting for a first view on the picture.
Being a 15 year veteran of online communities, I know that answering a question with a for-profit commercial solution, which the one responding is affiliated with, is walking a fine line. So here I go, walking that line. I'll do my best to address the question specifically. Let's start with a standard disclaimer...
DISCLAIMER: I am a principle in the service described below.
Yes, writing your own libraries is no fun for most (but us poor, twisted souls with nothing better to do), considering that the library you write or include may be considered out-dated within days of your modifications.
Maintaining such libraries are significantly time consuming, and once it becomes significantly time consuming such libraries are often either abandoned or sparsely updated. This is usually how commercial solutions are born.
I'm a big fan of Open Source, and there is no doubt that I've personally benefitted greatly from it over the years. For the great majority of you reading this, the above options are perfectly sufficient, as many of you are capable of developing the solutions you need yourselves or modify the available tools to suit your needs, and have the time to do so.
For those of you, however, that do not wish to build your own applications, debug and troubleshoot them, update the email processing definitions consistently and often, InboxResponse.com offers email bounce processing as an SAAS solution. It is:
A free trial is available at the following URL: https://inboxresponse.com/free-trial/
May not have been exactly what you were looking for (an Open Source library always kept up-to-date), but I don't think exactly what you are looking for is presently available.
Hope that helps someone!
I'm a large fan of the ezComponents library, which includes a Mail component which can handle both sending, and parsing mail (as well as connecting to your MTA to retrieve it. http://ezcomponents.org/docs/tutorials/Mail#mail-parsers
Reading through the docs, it seems like it should be up to your task.
After finding no simple answers to this question, I found this excellent solution on github:
https://github.com/cfortune/PHP-Bounce-Handler
its easier than you think to write this yourself.
You simply set the bounce back path in the headers. Then set up that email address to run a processing script. you obviously would need to send some form of user id.
I have used PHPList before and find it fine, there are better services to do what you need but obviously there is a cost for them.
Bounces occur when the address doesn't exists or the mail server sends it back. Some mail servers will not reply (as a security feature) so accuracy won't be the best.
A lot of the standalone/libraries offer extra features working out which links were clicked and by who working out who read the email. etc
these things are easy to achieve but take resources.
Let me know if there is anything else you need help with