Andre_br has asked for the wisdom of the Perl Monks concerning the following question:

Hello esteemed code fellows

Tired of receiving a couple thousands of mail bounces a day, I'm trying to figure out how to build a script that can work as a non valid email addresses parser.

The idea is to trigger it through the mail alias, and make it read the email address that had delivery problems, and also the cause. This way, I can freeze that user on the DB, so his sales stop (the guy's email has problems, so I'd better stop offering people his merchandise).

The error message that comes at the message body seems not to be a very regular pattern. But I noticed that all the delivery error messages come with a "delivery report.dat" file, wich seems to have a perfect regular pattern for parsing. Below some examples of their contents.

Reporting-MTA: dns; me.mysite.com X-Postfix-Queue-ID: AC07B204DA X-Postfix-Sender: rfc822; me@mysite.com Arrival-Date: Sun, 2 Nov 2008 09:01:23 -0200 (CST) Final-Recipient: rfc822; vivafonte@hotmail.com Action: failed Status: 5.0.0 Remote-MTA: dns; mx4.hotmail.com Diagnostic-Code: smtp; 550 Requested action not taken: mailbox unavail +able Reporting-MTA: dns; me.mysite.com X-Postfix-Queue-ID: 77B42205D8 X-Postfix-Sender: rfc822; me@mysite.com Arrival-Date: Sun, 2 Nov 2008 10:00:07 -0200 (CST) Final-Recipient: rfc822; r929302@metroweb.sp.gov.br Action: failed Status: 5.4.4 Diagnostic-Code: X-Postfix; Host or domain name not found. Name servic +e error for name=metroweb.sp.gov.br type=A: Host not found Reporting-MTA: dns; me.mysite.com X-Postfix-Queue-ID: B7EB92052C X-Postfix-Sender: rfc822; me@mysite.com Arrival-Date: Sun, 2 Nov 2008 10:00:04 -0200 (BRST) Final-Recipient: rfc822; cronusmg@yahoo.com Action: failed Status: 5.0.0 Remote-MTA: dns; f.mx.mail.yahoo.com Diagnostic-Code: smtp; 554 delivery error: dd This user doesn't have a yahoo.com account (cronusmg@yahoo.com) [-5] - mta208.mail.mud.yaho +o.com

Has anyone built something like this? I am not sure about how to do the parsing of this .dat file inside the email message.

Thanks a lot, fellows

Andre

Replies are listed 'Best First'.
Re: Mail Delivery System report parser
by GrandFather (Saint) on Nov 03, 2008 at 19:58 UTC