procmail
[Top] [All Lists]

Re: Bouncing Bad Addresses

2002-06-28 16:23:39
At 14:32 2002-06-28 -0700, Tom Most wrote:
I need to create a bounce recipe which will be at the end of a rather
lengthy .procmailrc that will bounce any other email which does not
match any email address in .procmailrc.  All addresses on this server are
routed though Procmail.

I'd advise against that. Spam will probably make up the bulk of those bounces, and since the MTA has already accepted the message, in order to bounce, you'll have to initiate a fresh SMTP connection - versus just declining to accept the message.

Furthermore, this implies that you may be trying to use Procmail as an MTA - something which Procmail is not well suited to. BCCs and multiple local recipients will bite you every time. You should use the MTA as an MTA.

I have written the recipe through the point of extracting the From: and
changing the To: to the from value, rewritting the Subject: (Delivery
Failure), and placing a short message explaining that the address is
invalid in the body.

Joy, yet another form of bounce message for mailing lists to attempt to make sense of. Please at a bare minimum, attempt to make it look just like a sendmail-generated MTA bounce for user unknown - down to the DSN values.

What has me stumped: I would like to echo the original header and body
at the end of the new body.  Any suggestions?


Basically:

:0
| ( cat sometemplatefile - | formail options ) | $SENDMAIL recipient

Or something similar. OTOH, you could have a template file that isn't static text but rather contains tokens which you replace - the recipient name (which I trust you have some magical way of pulling out of the ether at a non-MTA delivery stage) and your hostname for instance:


[auto-reply/BOUNCEUNKUSER]
This is an automatically generated Delivery Status Notification.

Delivery to the following recipients failed.

       %RECIPIENT%



Reporting-MTA: dns;%MYHOST%
Received-From-MTA: dns;%MYHOST%
Arrival-Date: %DATE%

Final-Recipient: rfc822;%RECIPIENT%
Action: failed
Status: 5.0.0
Diagnostic-Code: smtp;550 unknown user <%RECIPIENT%>

[end auto-reply file - not including these delimiters]


# You should deal with your own mail looping.
# Set LOOPALERT as appropriate.
# set AUTOREPLY to the dir where the template would be found.
# Set REPLYTO to the address which you're going to send the bounce to.

BOUNCEMSG=BOUNCEUNKUSER
BOUNCESUBJ="Delivery Status Notification (Failure)"
BODYBOUNCE=y
BOUNCER="postmaster(_at_)your(_dot_)domain(_dot_)tld"
INCLUDERC=bouncer.rc
#------------------



# [bouncer.rc]
# BOUNCEMSG = message file for bounce message (just the filename, we
#       expect to find it in $AUTOREPLY/)
# BOUNCESUBJ = subject text for the bounce message.
# BODYBOUNCE = if non-null, this causes the BODY of the message to be
#       bounced, but not the outer message (usually used for admin bounces
#       such as nonmember submissions)

# if BODYBOUNCE isn't empty, set the option to 'b' for processing the BODY
:0
* ! BODYBOUNCE ?? ^^^^
{
        BODYBOUNCE=b
}

:0$BODYBOUNCE
* $! REPLYTO ?? @(127\.0\.0\.1|localhost)\>
* $! REPLYTO ?? ^[      ]*(mailer-daemon|postmaster)@
| ( sed -e "s/%RECIPIENT%/$RECIPIENT/" \
        -e "s/%MYHOST%/`hostname --fqdn`/" \
        -e "s/%MYHOST%/`date "+%a, %e %b %Y %T %z"`/" templ.1 | \
        formail -I "Subject: $BOUNCESUBJ" \
        -I "To: $REPLYTO" \
        -I "X-Loop: $LOOPALERT" \
        -I "From: $BOUNCER" ; sed -e "1d" ) | $SENDMAIL -t -f $BOUNCER

# Execution will fall here only if preceeding wasn't run,
# due most likelt to an issue with reply address.
# (do whatever you will with failed messages)


The above is extracted from some code of mine, and while the larger script from which it is used works great, the above as-is is not tested, as per my disclaimer. Make sure your hostname and date support the gnu extensions used here, or find an alternate (the date string could be extracted from the From_ line of the received message - technically, that would be slightly more appropriate, but hey - you're using Procmail as an MTA, so what does it matter?).

Note: if you return a recipient name which isn't the same as the actual envelope recipient, the sender will be perplexed at what address really failed. This sort of BS is annoying for list administrators who have to do a bunch of testing to figure out what address which is subscribed to their list is causing the bounce. Consider carefully whether this approach is correct.

---
 Sean B. Straw / Professional Software Engineering

 Procmail disclaimer: <http://www.professional.org/procmail/disclaimer.html>
 Please DO NOT carbon me on list replies.  I'll get my copy from the list.

_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

<Prev in Thread] Current Thread [Next in Thread>