Reputation: 12512
I am working on a tool that will be sending bulk messages (not spam :) and I need to add a feature that will detect bounced messages. Is there a standard response associated with bounces? Would it be in the header of the body?
Upvotes: 1
Views: 2204
Reputation: 45045
If your tool is going to be talking directly to the recipients' SMTP servers, it might be more advisable to check the error codes returned via the SMTP protocol for 4xx (temporary failure, e.g. "mailbox full") or 5xx (error, e.g. "no such user") responses. Due to antispam/backscatter prevention mechanisms, you shouldn't rely on the recipient's server to reply with a non-delivery report whenever a message doesn't go through.
Upvotes: 1
Reputation: 53563
You can not rely on either the headers or the body of the bounced message to be able to reliably identify the original recipient, especially if you want to automate the process. Even if you add your own custom headers, it's likely that the bouncing server will strip them when it sends notification back to you. And trying to parse text in the body of the message in order to pull out the recipient's email address can be dodgy at best, as there's no standard format and every bounce you get will be different. The only piece of information that will remain completely untouched in a bounce is the return path email address -- the address that your server advertises it wants bounces sent to. Thus, the only way to automate truly accurate bounce catching is to encode the recipient directly into the return path address itself.
This would typically be done by overriding your server's default return path address for each outgoing message, using a unique value per recipient, like [email protected], where XXXXX is some encoded and/or obfuscated representation of the recipient's email address or some other internal identifier. This technique requires the use of an email server which can support this type of wild card catch-all address so that you don't have to set up a new bounce account for each email address you're sending to. Assuming that, you simply configure the server to dump all such bounce-* emails to your script, which needs only to decode the XXXXX in order to determine who the original recipient was.
Upvotes: 3
Reputation: 32031
This is typically achieved by setting the Return-Path
header of your outgoing Mail to a unique Address for every recipient. For example, you could use [email protected]
if you have a unique userid identifing every recipient.
If the Mail gets bounces, you recieve it and parse the reciever (which will [email protected]
), you can then take appropriate actions.
Using the +
syntax makes it possible to create a single mail-user ([email protected]
) which recieves all bounces and still distinguish between the recipients.
Upvotes: 4