Monday, October 8, 2012

Postfix Restrict Senders or Recipients

Source: http://www.linuxmail.info/postfix-restrict-sender-recipient/

This article describes how to configure Postfix to restrict mails from a sender, to a recipient, or both.

Restrict Sender

This section describes how to allow/reject a specific sender or a specific domain.
Edit main.cf
1. Edit the file /etc/postfix/main.cf and add the line below.
smtpd_sender_restrictions = 
  check_sender_access hash:/etc/postfix/sender_access
Edit sender_access
2. Create the file /etc/postfix/sender_access and review the example below.
janedoe@acme.local  REJECT
bugsbunny@acme.com  OK
acme.com            REJECT
Edit sender_access
3. Type in the command below in a terminal window to create a hash file.
postmap /etc/postfix/sender_access
CentOS 5 Service Configuration4. Restart the Postfix or MailScanner service. Learn how to restart services.

Restrict Recipient

This section describes how to allow/reject a specific recipient or a specific domain.
Edit main.cf1. Edit the file /etc/postfix/main.cf and add the line below.
smtpd_recipient_restrictions = 
  check_recipient_access hash:/etc/postfix/recipient_access,
  reject_unauth_destinations
Edit recipient_access
2. Create the file /etc/postfix/recipient_access and review the example below.
janedoe@acme.local  REJECT
bugsbunny@acme.com  OK
acme.com            REJECT
postmap recipient_access
3. Type in the command below in a terminal window to create a hash file.
postmap /etc/postfix/recipient_access
CentOS 5 Service Configuration4. Restart the Postfix or MailScanner service. Learn how to restart services.

Restrict Sender and Recipient

This section describes how to restrict both the sender and recipient. Example usage of this is when you have a private domain which should not be allowed to send to the internet.
Edit main.cf1. Edit the file /etc/postfix/main.cf and add the lines below.
smtpd_recipient_restrictions = 
  check_sender_access hash:/etc/postfix/sender_access,
  reject_unauth_destinations

smtpd_restriction_classes = local_only
local_only = check_recipient_access hash:/etc/postfix/local_domains, 
  reject
Edit sender_access
2. Create the file /etc/postfix/sender_access and review the example below.
acme.local  local_only
Edit local_domains
3. Create the file /etc/postfix/local_domains and review the example below.
acme.local  OK
Edit sender_access
4. Type in the command belows in a terminal window to create the hash files.
postmap /etc/postfix/sender_access
postmap /etc/postfix/local_domains
CentOS 5 Service Configuration5. Restart the Postfix or MailScanner service. Learn how to restart services.

No comments: