Posted By:
Christopher_Koenigsberg
Posted On:
Sunday, May 18, 2003 05:43 PM
What you ask is a very hard problem, and I don't know of anyone who has ever written the code to "do it right". (maybe my experience is out of date by now though; have you Googled for this yet?)
If you only deal with very well-behaved mailers, your task is easier, but the pathological cases will drive you crazy.
You can study the RFC's for standard classes of numerical error codes in the SMTP dialog e.g. your "550" error. Then you can study the RFC's for standard DSN formats (Delivery Status Notification).
And you may be able to write code to handle most common errors from well-behaved mailers, as I said, either in the SMTP dialog itself, or in the DSN's returned to you eventually/hopefully by remote mailers (once you've gained experience enough, and have collected enough bounced errors etc., to see which are the most common ones, from the mailers you mostly have to deal with given your particular audience of recipients).
Remember also that any one of the MTA's (Mail Transfer Agents, mailers e.g. SMTP servers), along the chain to your destination, may experience a problem completing the SMTP transmission to the next one in the chain, and may retry for perhaps like 5 days, before permanently giving up. So you may continue to get bounces from retries for days and days afterwards, on a particular message, and sometimes it is very hard to identify the original message that caused the retries. The worst cases are crappy proprietary mail gateways (like old Microsoft Mail, QuickMail etc.), and/or X.400 gateways. Also some of the worst cases come from complicated situations when someone has their mail aliased, forwarded, re-sent etc., off to some other set of addresses or mailing list, and one of them bounces, and the bounces don't contain the original destination address, etc. etc..
Everybody I've ever heard of, working on mail systems, has had to hack their own, to take care of the cases/examples they are familiar with, from their experience, from their own accumulated collection of bounced errors etc. and as I said, my experience is some years out of date so the worst of the older mailers may have been mostly retired/phased out by now (at least you won't have to deal with CSNet, BITNet, UUCP etc. relays anymore, hopefully), but I don't know what kinds of nasty new ones are out there...
Perhaps a neural network would be a new way to approach this problem, and "train" it on a large collection of different kinds of errors which you have parsed and classified by hand, in advance.