Mail

Restrict some users to sending mail only to internal domain

Postfix logoPostfix is a highly flexible MTA that can be configured to suit your needs. This article explains how to restrict selected users to sending email only to specified domains, or only within the company. We need to create two lookup tables. The first restricts which users can send email (the restricted_senders file here). The other defines which domains those users may send to (the local_domains file here). Configure selected users to send email only within the company or to specified domains

  1. Edit /etc/postfix/main.cf and add:

    smtpd_recipient_restrictions = check_sender_access hash:/etc/postfix/restricted_senders
    smtpd_restriction_classes = local_only
    local_only = check_recipient_access hash:/etc/postfix/local_domains, reject
  2. Create restricted_senders in /etc/postfix/ with:

    [root@Ezylinux ~]# vi /etc/postfix/restricted_senders

    Enter the email addresses to restrict to internal delivery, followed by local_only. Example:

    [email protected]      local_only
    [email protected]      local_only

    After creating the file, run:

    [root@Ezylinux ~]# cd /etc/postfix/
    [root@Ezylinux ~]# postmap restricted_senders
  3. Create local_domains in /etc/postfix/ with:

    [root@Ezylinux ~]# vi /etc/postfix/local_domains

    Enter the domains that addresses in restricted_senders may send to, followed by OK. Example:

    ezylinux.com     OK

    After creating the file, run:

    [root@Ezylinux ~]# cd /etc/postfix/
    [root@Ezylinux ~]# postmap local_domains

When testing delivery to different domains with a restricted user, the system returns an email containing the following error if the user is not allowed to send there.

554 5.7.1 : Sender address rejected: Access denied;
EOF.← Back to articles