I want to DISCARD incoming mail that matches blacklist instead of REFUSING it. How to change sendmail for this?

In sendmail.mc, I am using a blacklist feature to block CHINA, because this one server receives over 50,000 incoming mails on a daily basis that are refused as a result.

It reads:
FEATURE(`dnsbl', `cn.countries.nerd.dk', `"450 Mail from suspected spam source " $`'&{client_addr} " refused - using DNSBL countries.nerd.dk"')

In sendmail.mc, it then looks like this:
# DNS based IP address spam list cn.countries.nerd.dk
R$*                     $: $&{client_addr}
R::ffff:$-.$-.$-.$-     $: <?> $(host $4.$3.$2.$1.cn.countries.nerd.dk. $: OK $)
R$-.$-.$-.$-            $: <?> $(host $4.$3.$2.$1.cn.countries.nerd.dk. $: OK $)
R<?>OK                  $: OKSOFAR
R<?>$+                  $#error $@ 5.7.1 $: "450 Mail from suspected spam source " $&{client_addr} " refused - using DNSBL countries.nerd.dk"

I would like to rewrite it so it DISCARDS matches instead of REFUSING them.

I assume this line needs to be rewritten:
R<?>$+                  $#error $@ 5.7.1 $: "450 Mail from suspected spam source " $&{client_addr} " refused - using DNSBL countries.nerd.dk"

and I need guidance in doing so.
Who is Participating?
PsiCopConnect With a Mentor Commented:
Using the "dnsbl" FEATURE of sendmail will result in a DISCARD instead of a REJECT. In order to change that behaviour you'll need to:

1) Hack cf/feature/dnsbl.m4 and replace the line that reads:

R<?>$+                  $#error $@ 5.7.1 $: _DNSBL_MSG_

with something like:

R<?>$+                  $#discard $@ 5.7.1 $: _DNSBL_MSG_

2) Don't use FEATURE(dnsbl) - instead, create a LOCAL_CONFIG section in sendmail.mc (at the bottom, after the MAILER statements) and copy cf/feature/dnsbl.m4 into there and change the "error" to "discard" in your version of it. Don't forget to set the RBL hostname correctly.

Method 2) takes a little more work, but can easily be ported between platforms and sendmail versions, whereas with method 1) you'll need to remember to re-hack cf/feature/dnsbl.m4 every time you upgrade or work on a different machine.
Are you sure?

Discarding (takes place after accepting and) consumes more resources than refusing to accept.
Discarding is against spirit of "SMTP contract" to deliver or send back bounce message after giving ACK to the final dot of the message.
innsitesAuthor Commented:
Thank you for your detailed response.

I modified dnsbl.m4 as suggested with this
R<?>$+                  $#discard $@ 5.7.1 $: _DNSBL_MSG_

But this error shows in maillog as a result:

Jul  8 16:49:00 mythos sendmail[8719]: NOQUEUE: SYSERR(root): /etc/sendmail.cf: line 1053: invalid rewrite line "R<?>^A+                  ^A#discard ^A@ 5.7.1 ^A: "450 Mail from suspected spam source " ^A&, " refused - using DNSBL countries.nerd.dk"" (tab expected)

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

innsitesAuthor Commented:
Response to anfi

The refusals are creating problems with resulting excessive mqueue sizes.
I don't know what tool you used to modify dnsbl.m4, but whatever you used, it was the wrong thing. Hopefully you retained an unaltered copy. Try using vi, pico, or nano... and remeber that TAB is the whitespace character in sendmail Rulesets, not spaces.
anfiConnect With a Mentor Commented:
FEATURE(`dnsbl',...) rejects message before DATA command (before message itself is transfered).
It does not put any message in your server queue.

Your server refuses to accept the message => it makes cinnecting host responsible for generating bounce messages (NOT YOUR HOST).
anfi is right, by the way. Both about DISCARD being RFC-impolite, and about the point at which FEATURE(dnsbl) rejects the E-Mail.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.