Gossamer Forum
Home : General : Perl Programming :

Bounced Mail Handling

Quote Reply
Bounced Mail Handling
In continuation of a discussion that started in:

http://gossamer-threads.com/p/62284

I'm trying to handle bounced mail.

While it would be great to handle it pre-bounce, the only _real_ way is to handle it post bounce. The reasons, are many, since many servers will accept all incoming mail, try to deliver it, then bounce it. The only thing you can do is see if the server is alive, ask it if it will accept mail for this address and 'assume' it's going to be delivered if the answer is 'yes' or consider the address 'dead' if the answer is no.

I sent out a mailing to my list, and got 120+ bounces. Manually trying to deal with that is going to be a real pain.

I'd like to have an automated way to deal with the Links email addresses, in a way similar to 'verifying' links. Then, addresses that are reported as dead (bounced) are automatically removed by parsing out the bounce file.

Anyone have a system? I've downloaded a half dozen modules from CPAN to try to go through, but none seem to do it all, or do it the way needed for this sort of project.

PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://postcards.com/FAQ


Quote Reply
Re: Bounced Mail Handling In reply to
Straight from perldoc perlfaq9:

How do I check a valid mail address?
You can't, at least, not in real time. Bummer, eh?

Without sending mail to the address and seeing whether there's a human on the other hand to answer you, you cannot determine whether a mail address is valid. Even if you apply the mail header standard, you can have problems, because there are deliverable addresses that aren't RFC-822 (the mail header standard) compliant, and addresses that aren't deliverable which are compliant.

Many are tempted to try to eliminate many frequently-invalid mail addresses with a simple regex, such as /^[\w.-]+\@([\w.-]\.)+\w+$/. It's a very bad idea. However, this also throws out many valid ones, and says nothing about potential deliverability, so is not suggested. Instead, see http://www.perl.com/CPAN/authors/Tom_Christiansen/scripts/ckaddr.gz , which actually checks against the full RFC spec (except for nested comments), looks for addresses you may not wish to accept mail to (say, Bill Clinton or your postmaster), and then makes sure that the hostname given can be looked up in the DNS MX records. It's not fast, but it works for what it tries to do.

Our best advice for verifying a person's mail address is to have them enter their address twice, just as you normally do to change a password. This usually weeds out typos. If both versions match, send mail to that address with a personal message that looks somewhat like:

Dear someuser@host.com,
Please confirm the mail address you gave us Wed May 6 09:38:41
MDT 1998 by replying to this message. Include the string
"Rumpelstiltskin" in that reply, but spelled in reverse; that is,
start with "Nik...". Once this is done, your confirmed address will
be entered into our records.
If you get the message back and they've followed your directions, you can be reasonably assured that it's real.

A related strategy that's less open to forgery is to give them a PIN (personal ID number). Record the address and PIN (best that it be a random one) for later processing. In the mail you send, ask them to include the PIN in their reply. But if it bounces, or the message is included via a ``vacation'' script, it'll be there anyway. So it's best to ask them to mail back a slight alteration of the PIN, such as with the characters reversed, one added or subtracted to each digit, etc.

HTH,
--mark

Installation support is provided via ICQ at UIN# 53788453. I will only respond on that number.
Quote Reply
Re: Bounced Mail Handling In reply to
Mark,

Amazing how that cut/paste didn't answer the question at all.

Before I post, I read all the relavent information, and do pretty comprehensive searching. I think that would have been obvious from the "I've downloaded half a dozen modules from CPAN" statement.

To restate the problem:

I have a huge bounce mail file. I would like to retrieve all the bounced addresses, and remove them from the mailing lists, or create a dead_mail list and run existing emails through it first, sort of like a clean filter.

Additionally, it _is_ possible to check with a server to see if they are willing to handle the mail for a user. Some servers accept all mail, then bounce, others don't and refuse it right away. That would help eliminate a number of bad email addresses, and eliminate email addresses that are just plain bad. It's a step up from pinging the server to see if it's alive, and since many mail servers do not respond to a ping, it's actually a better method.

I do appreciate any help or insight. I don't appreciate smart-*ss responses that don't even attempt to deal with the question.

I'm trying to deal with the bounces and eliminate as many future ones as possible. Even most mailing list software requires manually dealing with bounced mail to the list.

PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://postcards.com/FAQ


Quote Reply
Re: Bounced Mail Handling In reply to
I though it did answer it, since the cruz was

In Reply To:
The only thing you can do is see if the server is alive, ask it if it will accept mail for this address and 'assume' it's going to be delivered if the answer is 'yes' or consider the address 'dead' if the answer is no.

I sent out a mailing to my list, and got 120+ bounces. Manually trying to deal with that is going to be a real pain.

I'd like to have an automated way to deal with the Links email addresses, in a way similar to 'verifying' links. Then, addresses that are reported as dead (bounced) are automatically removed by parsing out the bounce file.
Which said to me that you would like a way to contact the servers, find out if they are valid email address, and if not, remove the address from your Links (or mailing lists) files. Which is exactly what the response I gave answers:

In Reply To:
How do I check a valid mail address?
You can't, at least, not in real time. Bummer, eh?

Without sending mail to the address and seeing whether there's a human on the other hand to answer you, you cannot determine whether a mail address is valid.
Now that I read your response, I see you have made it more clear that you mean you would like to parse the bounced mail file and pull those addresses out of your links file. sorry, that wasn't clear to me the first time.

As that kind of problem is exactly what Perl was made for (parsing text) it would be quite simple to write a script to do that. I am not aware of any pre-existing ones. It would entirely depend on the format of your bounced mail file. Simply grep the log for email addresses, then matching those addresses in the Links files is trivial.

In Reply To:
I don't appreciate smart-*ss responses that don't even attempt to deal with the question
Mine was neither, it was an answer to a misunderstaning of your question. No need to be snotty.

--mark


Installation support is provided via ICQ at UIN# 53788453. I will only respond on that number.