That will probably generate lots of "backscatter".
You really want to reject senders/recipients/entire_messages during the
SMTP-dialog -- and let the sending host do the error handling.
Permanent failures returned by delivery agents (mailers) can only be
handled by sending back a "delivery failure notification" mail because
the message has already been accepted by your sendmail daemon.
In case of spam (currently the most likely source of invalid recipient
addresses) you'll almost certain send your failure notification to
a spoofed sender address.
I did a quick test to show this.
I created a ".procmailrc" file for a user with the following contents:
# --
# First set the EXITCODE. Code 67 is unknown user.
# --
EXITCODE=67
# --
# And finaly trash the message. Note that this recipe ALLWAYS
# succeeds. Any rule placed after this recipe wil NEVER be
# reached.
# --
:0:
/dev/null
And started an SMTP session.
kees@lankhmar:~$ telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 lankhmar.remmin.home ESMTP Sendmail 8.14.4/8.14.4; Thu, 10 May 2012
23:22:12 +0200
ehlo localhost
250-lankhmar.remmin.home Hello IDENT:1000@localhost [127.0.0.1], pleased
to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-EXPN
250-VERB
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-AUTH DIGEST-MD5 CRAM-MD5
250-DELIVERBY
250 HELP
mail from:<kees@localhost>
250 2.1.0 <kees@localhost>... Sender ok
rcpt to:<cjt@localhost>
250 2.1.5 <cjt@localhost>... Recipient ok
data
354 Enter mail, end with "." on a line by itself
from: <kees@localhost>
to: <cjt@localhost>
subject: bounce test.
blah
.
250 2.0.0 q4ALMCSg002170 Message accepted for delivery
quit
221 2.0.0 lankhmar.remmin.home closing connection
Connection closed by foreign host.
kees@lankhmar:~$
The smtp conversation shown above indicates that the message has been
accepted by sendmail. But the "local mailer" (procmail in my case)
rejected the message afterwards and a DSN message was sent as shown
by the mail logs:
May 10 23:24:00 lankhmar sm-mta[2170]: q4ALMCSg002170:
from=<kees@localhost>, size=71, class=0, nrcpts=1,
msgid=<201205102123....@lankhmar.remmin.home>, proto=ESMTP,
daemon=MTA, relay=IDENT:1000@localhost [127.0.0.1]
May 10 23:24:00 lankhmar sm-mta[2176]: q4ALMCSg002170:
to=<cjt@localhost>, ctladdr=<kees@localhost> (1000/100), delay=00:01:00,
xdelay=00:00:00, mailer=local, pri=30396, dsn=5.1.1, stat=User unknown
May 10 23:24:00 lankhmar sm-mta[2176]: q4ALMCSg002170: q4ALO0Sg002176:
DSN: User unknown
May 10 23:24:07 lankhmar sm-mta[2176]: q4ALO0Sg002176:
to=<kees@localhost>, delay=00:00:07, xdelay=00:00:07, mailer=local,
pri=31420, dsn=2.0.0, stat=Sent
So a "local mailer" doesn't seem to be the right place to handle
delivery attempts to unknown users.