How to Sendmail reject email to a local user *unless* it comes from a trusted subnet

emailsendmailspam

I have sendmail set up to accept mail for a few domains and to relay messages for a few subnets' worth of systems. Recently a particular internal-use-only address has been receiving a lot of spam. I've been asked to simply drop any mail destined for this address unless the mail originated from one of the computers for which this system will relay mail.

I know I can do this with procmail, but I'd prefer to tie it into sendmail so that nonconforming email will be rejected outright at the MTA level. I can't figure out how to get sendmail to do this (or whether it's even possible).

I have sendmail configured with the following settings:

FEATURE(`access_db', `hash -T<TMPF> -o /etc/mail/access.db')`
FEATURE(`blacklist_recipients')

/etc/mail/access contains:

example.com              RELAY
connect:192.168.15       OK
to:internal@example.com  REJECT

And I'm generating /etc/mail/access.db via makemap hash /etc/mail/access.db </etc/mail/access.

When I try to use that configuration, however, even local machines get 550 5.2.1 <internal@example.com>... Mailbox disabled for this recipient messages when trying to send to the internal address.

Can I configure sendmail to do what I want and, if so, how?

Best Answer

Sorry, I dont want to offend you, but is this the exact content of your /etc/mail/access.db?

example.com              RELAY    
connect:192.168.15       OK    
to:internal@example.com  REJECT

Cause it should be a hash map. The above should be the content of your /etc/mail/access. Then compile it to a map: makemap hash /etc/mail/access.db < /etc/mail/access