Re: Dealing with returned mail
by devnul (Monk) on Jun 21, 2005 at 02:04 UTC
|
Different mail servers may treat bounces different. Some reply to the From: header, others to a "Bounces-to:" header. Heck, there might even be other possibilities that I'm not thinking of.
You are just scratching the surface though of potential problems.
The mailbox could be temporarily over its limit, which is why it is bouncing. The server could be telling you it is unavailable and to try again later.
Not only that but the format of the bounce messages may be different. Some mail servers will tell you immediately that the mailbox is unavailable and it won't deliver, others will accept the message and may bounce it back to you even a week later with some cryptic message as to why it was not able to be delivered. I don't know of any easy ways to deal with these except that when you see something which is clearly a bounced message, write some code to automate dealing with it. This would involve having your script checking whichever mailbox is holding the message and acting appropriately, or to be setup in some way so each message which is delivered to that mailbox is instead processed by your script which checks to see if it is a bounce. If it is a temporary bounce (mailbox full, etc) how long do you want it to allow it to keep bouncing before it is removed?
I can't really give you any specific advice, because I don't know your system, how it is configured, or what your goals are, but I hope this helps gets you thinking about the challenge you have decided to undertake.
- dEvNuL | [reply] |
Re: Dealing with returned mail
by dave0 (Friar) on Jun 21, 2005 at 04:03 UTC
|
First, you need to solve the problem of getting the bounce message. To do this, make sure that your SMTP envelope sender is the address that should receive bounces, and proper RFC-compliant mailservers will send the bounces there.
Once that's done, you can use Mail::DeliveryStatus::BounceParser to parse the bounce message and figure out what addresses to remove. | [reply] |
|
|
If you're using an account specifically for sending messages to users in your list, I suggest setting up a .forward file in the home directory of that user and forward the mail to your bounce parser.
| [reply] |
Re: Dealing with returned mail
by Ultra (Hermit) on Jun 21, 2005 at 06:15 UTC
|
Also, a bounce message does not always indicate that the mail address is not valid anymore.
I'd store the mail address somewhere, and depending on your mailing list traffic, I'd wait for a certain time to see that if for all messages sent to that mailbox a bounce message comes back.
In this case, the address should be removed, otherwise, contact the owner and inform him/her that some problems had occurred, .
| [reply] |
Re: Dealing with returned mail
by redhotpenguin (Deacon) on Jun 21, 2005 at 06:00 UTC
|
I've written a plugin for Qpsmtpd which does something like this in a perl application. It parses the email, and if it's a bounce takes an action based on the email address.
It may not work on shared hosting though, and for that you may want to create an email gateway which triggers a perl script. Take a look at Request Tracker's gateway interface as an example. Have your perl script filter the email for bounces, and take action if a bounce is identified, otherwise send the email on it's way. | [reply] |
|
|
If you're using exim as your MTA you can set up a system filter to identify bounce messages for you. For example:
if error_message
then
pipe "/usr/local/bin/handlescript"
finish
endif
will pipe all bounce messages to your script and then discard them. That way your perl script only gets called for true bounce messages, which reduces the overhead.
If you want the bounced email to be delivered to the script but also to the original sender, just omit the "finish" keyword. | [reply] [d/l] |
Re: Dealing with returned mail
by weierophinney (Pilgrim) on Jun 21, 2005 at 11:40 UTC
|
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! | [reply] |
|
|
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?
| [reply] |
Re: Dealing with returned mail
by grinder (Bishop) on Jun 21, 2005 at 07:50 UTC
|
How can I update the script so that it sees the returned emails, and removes them from the mailing list?
Ask your hosting service if they offer Mailman for managing mailing lists. It takes care of removing dead addresses automatically, which greatly simplifies the management of large mailing lists. Yes, it's written in Python, but so what? It does its job and leaves you free to pursue more interesting things.
Even if your ISP doesn't offer Mailman, they may offer a similar application. Ask them, and find out how they can help you.
- another intruder with the mooring in the heart of the Perl
| [reply] |
Re: Dealing with returned mail
by saintmike (Vicar) on Jun 21, 2005 at 00:03 UTC
|
There's a nice FAQ on that. | [reply] |
|
|
I don't think he was asking how to validate an email address.
- dEvNuL
| [reply] |