Sendmail: how to restrict delivery based on "to" or "from"?

Hello,

I manage a large sendmail server that handles more than 20,000 pieces of mail per day. It's a bit unusual in that all this mail is only being sent to and from 4 local accounts. (It's an automated transaction processing system, whereby users submit a transaction via email attachment). I've got Sendmail configured to use Procmail for local delivery. My Procmail recipe then calls Cyrus Deliver for final message delivery into my Cyrus IMAP database. The four local mail accounts exist only within the Cyrus IMAP database, they are not unix user accounts on the system.

My problem is that Sendmail, when it receives a piece of incoming mail, has no way of determining if it's addressed to a valid account or not. It simply hands the mail to Procmail and lets procmail sort it out. Unfortunately, if someone makes a typo in the destination address, procmail simply drops the mail into a black hole and the person who submitted it never knows what happened!

For example, lets say one of my mail accounts is named Process@mydomain.com. If someone accidentally sends the mail to Lrocess@mydomain.com he does not receive any kind of rejection notice. Sendmail gladly accepts the message, hands it to Procmail for delivery, and then Procmail delivers it into an errors folder.

My understanding is that invalid account rejection should happen at the Sendmail level. How do I implement this in Sendmail? Here is the local delivery portion of my Sendmail.cf file:

# Cyrus Mailer using Procmail
Mprocmail, P=/usr/bin/procmail, F=lsDFMnPqA5@, S=10, R=20/40, T=X-Unix,
U=cyrus:mail,
A=procmail -p /etc/procmail/procmail.global CYRUSUSER=$u

I want Sendmail to call Procmail only for the four valid local accounts. For all other incoming mail, I want Sendmail to automatically bounce it back to the sender with an appropriate "invalid recipient" message.

Does anyone know how to do this? Thank you

Remove procmail as the default delivery in the sendmail configuration.
Add 4 entries to the alias file so that:

process1: |/usr/bin/SendtoProcmail
process2: |/usr/bin/SendtoProcmail1 (if the processes are different for each recipient)
etc
Run newaliases.
Any mail not for process1-4 will be returned with a user not found message.

1 Like

Interesting, I didn't know the aliases file could be used in that way. Thanks, I'll do some testing with it. :b: