| Recommend this page to a friend! |
| PHP MIME Email Message Parser | > | All threads | > | Extracting Bad Email Address | > | (Un) Subscribe thread alerts |
| |||||||||||||||
Greetings Manuel:
Hope all is well with you. You helped me over a year and one-half ago on using your mime_parser family of scripts to extract bad email address from a pop3 mailbox. I have set up a"bademail" pop3 account on our server and you assisted me with identifying where in the data structure the bad enmail address was located. Below is the code snippet I used that used to extract the bad emiall adresss out successfully: echo '<h2>MIME message decoding successful</h2>'."\n"; echo '<h2>Message structure for Email ' . $i . '</h2>'."\n"; echo '<pre>'; print_r($decoded[0]); print "i=$i<br>"; print_r($decoded[0]['ExtractedAddresses']['envelope-to:'][0]['address']); $bad_address=$decoded[0]['Headers']['x-failed-recipients:']; $bad_address=trim($bad_address); print_r($decoded[0]['Headers']['x-failed-recipients:']); print "<b># $i Bad EMail Address is $bad_address</b><br>"; $bad_address used to return the address, now it does not. We have moved to a different host provider and is it poosible a php version upgarde "broke" something. Thanks again for all of your assistance. Jack
Using x-failed-recipients header is not a standard way to determine which addresses are bouncing. That is why it stopped working.
If your mail server sends delivery status report notification messages when a delivery fails, the MIME parser class can parse those messages and extract the bouncing addresses.
Thank you Manuel.
my pop3 account that I am having all the bounced email sent to contains notifications for my host provider and others. My question is what is the data structure I have to parse to extract the bad email address? $bad_address=$decoded[0]['Headers']['x-failed-recipients:']; if I should not be looking for it here, whre should I be? Thank you again for all of your helpful assistance. Jack
As I said, the MIME parser class is already capable of parsing bounce messages formatted according to the e-mail standards and extract the bouncing addresses. Standard bounce messages do not use those non-standard headers. It is a different structure.
If you are not sure if the bounce messages you are getting are formatted according to the standards, just send me a sample bounce message so I can I tell you what you can do.
Thank you Manuel
Below are links to three .eml messages alhloghomes.com/mimeparser/test/sam ...alhloghomes.com/mimeparser/test/sam ...alhloghomes.com/mimeparser/test/sam ...I appreciate your efforts! Jack
Happy New year Manuel! Hope you had happy holidays...
Just checking to see if you had a chance to look at the three same email files I have a link for in my previous message? Thank you Jack
Sorry for the delay. Inadvertently I marked as read the alert message that I got of your last response.
Anyway, the first message is a typical qmail bounce. It is not formatted according to any standard. It is possible to parse its content with regular expressions but it would be unreliable. It is better to use a catch all e-mail address to get all bounced messages and make each message return-path address be set to something that lets you extract the original recipient address. It may be something like [email protected], where the recipient address is [email protected] and your domain is yourdomain.tld. I associate a POP3 account with the domain catch all address. Then I use the POP3 class to poll messages delivered to the catch all mailbox. Those messages that have the To: address matching the format above will be processed as bounces. The others are ignored. I use that in the PHPClasses site and works reliably. As for the other 2 messages, they are formatted in standard bounced message format but there was a bug in the MIME parser class that prevented to parse the bouncing address correctly when the line breaks are just new lines. The bug was fixed and the fixed version of the class was uploaded.
I apologize for my delay. Where I live in the U.S. we have been hit with 12+ inches of snow the last three days and I have been busy shoveling snow:)
I looked @ my POP3 email account that is receiving the bounced emails and I noticed that over 90% are in the qmail format and they are coming from my web host provider. The others are coming from other providers. I understand the "logic" behind your strategy for appending an email recipient's email address to the catchall pop3 email account but I am not sure how to implement it. Please read my comments below each of your points in your previous reply: (Manuel) It is better to use a catch all e-mail address to get all bounced messages and make each message return-path address be set to something that lets you extract the original recipient address. It may be something like [email protected], where the recipient address is [email protected] and your domain is yourdomain.tld. (Jack) I have a pop3 account set up as '[email protected]'. We have a small mailing list where we occasionally send out a newsletter. In my current message return-path I have Return-Path: [email protected]. Now let's say I am sending an email to my real email address 'jack.utano@comcast' but my address in our database is misspelled '[email protected]'. In your example above '[email protected]' would be '[email protected]' I associate a POP3 account with the domain catch all address. Then I use the POP3 class to poll messages delivered to the catch all mailbox. Those messages that have the To: address matching the format above will be processed as bounces. The others are ignored. Now, here is where I am confused. I am assuming in my example my domain catch all POP3 account is '[email protected]'. If I set 'Return-Path: [email protected]' how does the mail server know to associate this return path to my catchall POP3 [email protected]??? Thank you for your endless patience:) BTW, have you ever had snow where you live in Portugal?
It just dawned on me what you meant by "catchall" email account. I remember on our last web host provider, I was able to create a catchall account where any email sent to alhloghomes.com that did not have an existing email account setup would be sent to that catachall account.
If this is what you meant, my new we host provider disabled that feature because of "mail server issues" of getting too much spam. So I cannot create a "catchall" account. However, I looked at about two dozen of those qmail replies and each time I saw a way I could reliably parse out the bad email address. I turned decoding of the message body on $mime->decode_bodies = 1; ran my script on a few emails in the [email protected] and below is the output from one of the qmail messages: [Body] => Hi. This is the qmail-send program at outbound-ss-830.bluehost.com. I'm afraid I wasn't able to deliver your message to the following addresses. This is a permanent error; I've given up. Sorry it didn't work out. <[email protected]>: 66.94.236.34 failed after I sent the message. Remote host said: 554 delivery error: dd Sorry your message to [email protected] cannot be delivered. This account has been disabled or discontinued [#102]. - mta1149.mail.mud.yahoo.com When I use: print_r($decoded[0]); The top of the output for this email is as follows: <h2>Message structure for Email 2</h2> <pre>Array ( [Headers] => Array ( [return-path:] => <> [envelope-to:] => [email protected] [delivery-date:] => Fri, 08 Oct 2010 10:13:56 -0600 [received:] => Array ( [0] => from exprod7mx207.postini.com ([64.18.2.47] helo=psmtp.com)by box300.bluehost.com with smtps (TLSv1:AES256-SHA:256)(Exim 4.69)id 1P4Fa0-0004GP-ASfor [email protected]; Fri, 08 Oct 2010 10:13:56 -0600 [1] => from source ([69.89.31.100]) (using TLSv1) by exprod7mx207.postini.com ([64.18.6.13]) with SMTP;Fri, 08 Oct 2010 12:13:56 EDT [2] => from exprod7mx235.postini.com ([64.18.2.188] helo=psmtp.com)by box300.bluehost.com with smtp (Exim 4.69)id 1P4FZz-0004Et-6Jfor [email protected]; Fri, 08 Oct 2010 10:13:55 -0600 [3] => from source ([66.147.249.4]) by exprod7mx235.postini.com ([64.18.6.14]) with SMTP;Fri, 08 Oct 2010 11:13:55 CDT [4] => (qmail 17709 invoked for bounce); 8 Oct 2010 16:13:54 -0000 ) [date:] => 8 Oct 2010 16:13:54 -0000 [from:] => [email protected] [to:] => [email protected] [mime-version:] => 1.0 [content-type:] => multipart/mixed; boundary="1286554430outbound-ss-830.bluehost.com14730912" [subject:] => failure notice [message-id:] => <[email protected]> [x-remote-checked:] => box300.bluehost.com 1P4FZz-0004Et-6J 64.18.2.188 ) [Parts] => Array ( [0] => Array ( [Headers] => Array ( ) [Parts] => Array ( ) [Position] => 1301 [Body] => Hi. This is the qmail-send program at outbound-ss-830.bluehost.com. I'm afraid I wasn't able to deliver your message to the following addresses. This is a permanent error; I've given up. Sorry it didn't work out. <[email protected]>: 66.94.236.34 failed after I sent the message. Remote host said: 554 delivery error: dd Sorry your message to [email protected] cannot be delivered. This account has been disabled or discontinued [#102]. - mta1149.mail.mud.yahoo.com The email address positions are the same in two dozen or so I looked at. So, I was able to successfully parse out the bad email address from the body section: This is the output from my script now that extracts the bad email address for this example: mb=Hi. This is the qmail-send program at outbound-ss-830.bluehost.com. I'm afraid I wasn't able to deliver your message to the following addresses. This is a permanent error; I've given up. Sorry it didn't work out. <[email protected]>: 66.94.236.34 failed after I sent the message. Remote host said: 554 delivery error: dd Sorry your message to [email protected] cannot be delivered. This account has been disabled or discontinued [#102]. - mta1149.mail.mud.yahoo.com --- Enclosed are the original headers of the message. [email protected] GREAT! Now, for the other emails that are in standard bounced message format where in the decoded structure is the bad email address stored? Also, is there something in the structure I can automatically determine if the email is the non-standard qmail format or the standard format. I am close now because I can parse out the bad emails for the non-standard qmail format Thanks for all your help again...
The Analyze function returns an array with an entry named Recipients. That entry is an array with the details of all recipient addresses. The Address entry of that array contains the bounced address, in case of a delivery failure.
|
info at phpclasses dot org.
