Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: Dealing with returned mail

by weierophinney (Pilgrim)
on Jun 21, 2005 at 11:40 UTC ( #468636=note: print w/replies, xml ) Need Help??

in reply to Dealing with returned mail

As somebody else mentioned, make sure that the SMTP envelope sender is the email address to which you want to receive bounces. Ideally, you want this to be a unique user, so that as you handle emails, you can be fairly certain they're bounces only. Most MTAs will respect that address as the originating address; you can't do much about the others.

Then, on the machine that hosts that email address, you need to put in a filter of some sort. Check to see if your server has procmail or maildrop installed. Then write a recipe for that address that processes incoming mail, searching for bounces, and searching in bounces for the original recipient -- this is where perl comes in, as you'll have your filter call a perl routine that will scan the incoming mail. The method for doing so will vary based on the MTA you use, but most have some easily identifiable block within bounced mail showing the original headers, and you can use a regex on those. Then update your database.

Always keep in mind that a message may bounce because (a) a user's account has temporarily exceeded quota, (b) a user's MTA is temporarily down (power failure, maintenance), (c) old DNS for a user's host is cached in the MTA, etc. It's best not to remove a user based on a single bounce. Where I work, we remove a user based on a formula involving consecutive bounces and frequency with which we mail the user. This means that when we update our DB, we're actually incrementing a 'bounced' count. A cronjob then goes through the list later and checks those with high bounce counts to determine if they should be removed.

Good luck!

Replies are listed 'Best First'.
Re^2: Dealing with returned mail
by cosmicperl (Chaplain) on Jun 24, 2005 at 00:17 UTC
    Thanks everyone. Just one question. How should I formation the prints to sendmail so that the SMTP envelope sender and bounce to addresses are configured correctly? At the moment I'm just using an open command following by some print statements for the TO: FROM:, etc.

    Also do you think I could use POP3 to check the bounce email address? That way the script could be contained and run on any hosting account? Or aren't the pop3 modules included in the core?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://468636]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2020-12-04 08:09 GMT
Find Nodes?
    Voting Booth?
    How often do you use taint mode?

    Results (58 votes). Check out past polls.