I want to limit number of recipients for outgoing mail using Postfix sendmail. For example, I added default_recipient_limit=2 and default_destination_limit=2 to main.cf and reloaded Postfix, but testing it by sending more than 2 emails fails. Why is this not working and how do I fix it?
This is not working because smtpd_recipient_limit only applies to the emails received by smtpd daemon through an SMTP transaction. The emails submitted using the sendmail command is queued in the maildrop queue by the postdrop command, which is picked up by pickup and fed to cleanup directly.
You can't restrict recipient count for the mails submitted through sendmail command. The only solution to this problem is force your applications to send mail only through an smtp transaction.