I had a client ask me a while ago if i can block all email coming in for his domain but allow certain domains/emails to be able to send to him.

I managed to find an arcticle on it thanks to Winston!

Add this line to /etc/postfix/main.cf:

smtpd_restriction_classes = domain_class
domain_class =
check_sender_access hash:/etc/postfix/access_domain_class
reject

This will cause Postfix to pass the sender address of all e-mail classified as fredclass through the access table access_domain_class, and if it doesn’t get accepted there, it gets rejected.

The file /etc/postfix/access_domain_class should contain this sort of thing:

# These are for various technical reasons.
double-bounce@mx.mydomain.com OK
root@mx.mydomain.com OK
MAILER-DAEMON@mx.mydomain.com OK

# These are the good guys.
user@domain.com OK
domain.com OK

E-mail from the above addresses and domains to bob@domain.com will be accepted. All other sender addresses will be rejected.

After creating the file /etc/postfix/access_domain_class, run the postmap command on it:

hostname/# cd /etc/postfix
hostname/# postmap hash:access_domain_class
hostname/# /etc/init.d/postfix reload

Up to this point, we have only defined the class domain_class and created
the database file /etc/postfix/access_domain_class which says who is
permitted to send e-mail to bob@domain.com. Now we must tell Postfix
that all e-mail addressed to bob@domain.com is of class domain_class.

The main.cf should already have something like this:

smtpd_recipient_restrictions =
hash:/etc/postfix/access_recipient

This causes Postfix to pass the recipient address of all incoming e-mail through the table access_recipient.  In our case, we will not simply accept or reject e-mail to bob@domain.com. Instead we will just indicate that it is of class domain_class.

In the file /etc/postfix/access_recipient, this should appear:

bob@domain.com domain_class

This means that all e-mail addressed to bob@domain.com is classified as domain_class, which implies that the test check_sender_access hash:/etc/postfix/access_domain_class will be applied to all such e-mails in accordance with the rule in /etc/postfix/main.cf.

To activate the changes to the file /etc/postfix/access_recipient, do this:

hostname/# cd /etc/postfix
hostname/# postmap hash:access_recipient
hostname/# /etc/init.d/postfix restart

Share and Enjoy:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Add to favorites
  • FriendFeed
  • LinkedIn
  • Posterous
  • Reddit
  • RSS
  • Slashdot
  • StumbleUpon
  • Tumblr
  • Twitter
  • Blogplay