Pages

Wednesday, March 6, 2013

Specific email ID only receive mail from specific domains

Scenerio


Today one of my clients send an email. He has some group email IDs. He wants only native domain users can send mails to those group IDs. 

At first I thought how can it possible? How can I filter incoming mails to a specific email address? But by luck I use POSTFIX. It has lots of option to work with. Here is how I have done it......


 1. At first edit the main.cf file of postfix.


smtpd_recipient_restrictions = check_recipient_access hash:/etc/postfix/protected_destinations, permit_mynetworks, reject_unauth_destination

smtpd_restriction_classes = insiders_only

insiders_only = check_sender_access hash:/etc/postfix/insiders, reject

[Explanation: smtpd_recipient_restrictions is a postfix parameter, It will check the recipient access by "protected_destinations"- Lets see below what I will put in "protected_destinations"? ]

2. Edit and save the following in "/etc/postfix/protected_destinations"
    xyz@domain.com   insiders_only
    

[How do postfix knows insider_only?? It has been declared in main.cf with "smtpd_restriction_classes" after that I defined the "insiders_only" in postfix by "/etc/postfix/insiders".]

3. Now input /etc/postfix/insiders

   domain.com                      OK       ###matches my.domain and subdomains
   anotherdomain.com       OK       ###matches another.domain and subdomains

4. Now create .db for new files with following commands.

postmap /etc/postfix/insiders
postmap /etc/postfix/protected_destinations

5. Restart the postfix service.

/etc/init.d/postfix restart

So........... What will be the result??? Only domain.com and anotherdomain.com users can send mails to xyz@domain.com email ID.

Postfix.......... ROCKS.....!!! isn't it???

1 comment: