Postfix is not rejecting recipients addresses when mailx is used

Solution 1:

  • It is because smtpd_recipient_restrictions only apply to the mails received by smtpd daemon through an SMTP transaction.
  • The mails submitted using sendmail or mailx command is queued in maildrop queue by postdrop command, which is picked up by pickup and fed to cleanup directly.

You can't restrict recipients for the mails submitted through sendmail or mailx commands.

The only solution to this problem is force your applications to send mail only through smtp.

Solution 2:

As clement said, your restriction doesn't work because the email was queued via pickup.

As workaround you can apply a solution from postfix-users mailing-list

In master.cf look the pickup entry. Then add -o content_filter=smtp:[127.0.0.1]:12525

pickup    fifo  n       -       n       60      1       pickup
    -o content_filter=smtp:[127.0.0.1]:12525

Then add another smtpd process (port 12525) also in master.cf to perform rejection

127.0.0.1:12525 inet    n       -       n       -       25      smtpd

Don't forget to restart postfix

The caveats from the same page: This overrides the default delivery agent for locally submitted email, but adds to the already I/O overhead of local submission.