Postfix Limit mail for domain from IP range
I have multiple domains and email accounts on my postfix server. All of them get slammed with spam despite all my attempts to get it under control, I broke down and started paying for a pass external spam filtering service. Which helped tremendously.
One domain domain however is still getting slammed with spam. While investigating I noticed the spam is coming in directly to our server and not through the spam filtering service. So I am wanting to do is modify my Postfix configuration so that email for that domain name and only that domain name can be delivered from the Spam Filtering services IP addresses.
The reason why I am looking to do it on a by domain method is because a couple of the domains on the server did not have spam issues (more a matter of smart internet users). So I never signed them up for the spam server. This ruled out the ability to just set ip tables to allow smtp traffic only form the spam filtering service's IP Addresses.
Anyone got a way I can do this?
Edit: To clarify all mail (minus 1 or 2 domains) on the server is delivered to a outside spam service first. Then spam service does their magic and delivers it to us. So for a domain using this service if the SMTP traffic is not from the IP address of the Spam Service. I just want the mail rejected or sent into a black hole. As the DNS changes were made weeks ago. So and direct connection to the server for a domain using that spam service is going to be spam.
From your description, I'm translating your question to: how to setup postfix so
IF postfix receive an email with recipient domain is example.net AND IP address ism't IP address of spam filtering THEN send the email to spam filtering service.
The possible solution is using Postfix Per-Client/User/etc. Access Control a.k.a. Postfix restriction classes.
First you need to define the check_recipient_access
in your restriction stack, for example in smtpd_recipient_restriction
. Also define smtpd_restriction_classes
in main.cf
smtpd_restriction_classes = spamfiltering
smtpd_recipient_restriction =
check_recipient_access hash:/etc/postfix/spammydomain
...other restriction...
Then in main.cf
, we define the spammy domain, for example: example.net
example.net spamfiltering
Then in main.cf
define custom filtering for all IP address except spam filtering IP Address (for example 192.168.1.168)
spamfiltering = check_client_access cidr:/etc/postfix/spamfilter, permit
For file /etc/postfix/spamfilter
, put this line
192.168.1.168/32 PERMIT
0.0.0.0/0 REJECT
It will REJECT all email intended to example.net domain, except if it came from 192.168.1.168