Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We have postfix on our development server, and I'd like it to be able to only send mail to our domain, not to other domains, preventing outside users from accidentally receiving mail from our development server.

I searched through the docs, tried several things but it's still sending to all domains...

share|improve this question
up vote 2 down vote accepted

transport(5) maps are used to redefine how email is routed by postfix.

  • Add the following line to /etc/postfix/

transport_maps = hash:/etc/postfix/transport

  • Add the new file /etc/postfix/transport with this content: : : * discard:

Replace with the domain your mailserver should still send mails to. If you don't care about subdomains then remove the first line.

Don't forget to hash the file after editing it with postmap(1) and reload postfix so that the changes can take effect

# postmap /etc/postfix/access && postfix reload

share|improve this answer

So if someone stumbles over this like I did: the answer is indeed header_checks and it works as such:

  • Add the following line to /etc/postfix/

    header_checks = regexp:/etc/postfix/header_checks
  • Add the new file /etc/postfix/header_checks with this content:

    /^To:.*  DUNNO
    /^To:.*@/   REDIRECT

Replace with the domain your mailserver should still send mails to. Replace with the email address all other emails should be redirected to.

If you need to allow multiple domains, the first line should look like this:

/^To:.*@(|  DUNNO

Instead of redirecting you can simple drop all other mails. Replace the second line above with:

/^To:.*@/   DISCARD No outgoing mails allowed


  • Postfix goes through the mail headers one-by-one.
  • Each header line gets matched against the header_checks file line-by-line.
  • If it matches the first line (To: contains the allowed domain), it skips to the next header line and starts the header checks again from the top. Since no other line will match, this means the mail gets delivered.
  • If it matches the second line (To: contains another external email address), it redirects the mail.
share|improve this answer
this problem seems to have been solved with this answer, maybe it should be marked as solved? (it worked like a charm for me at least) – Sverre Dec 11 '14 at 5:18

You can easily restrict the recipients with standard smtpd_recipient_restrictions or more precisely check_recipient_access.

Just create an access(5) table /etc/postfix/access with the following content ( being the domain you want to allow to send mail to):    OK

You can also allow only some specific addresses:    OK    OK

Don't forget to hash the file after editing it with postmap(1):

# postmap /etc/postfix/access

Now put the following recipient restrictions in your

smtpd_recipient_restrictions = 

and reload Postfix:

postfix reload

After that, test it if it works.

share|improve this answer
That will work for mail sent via SMTP, not via /usr/lib/sendmail command and local processes can do both. It seems the 'authorized_submit_users' setting may be used to block local submission with sendmail/postdrop, then the smtpd restrictions will be enough. – Jacek Konieczny Feb 28 '10 at 10:23

Have you tried header_checks(5)?

share|improve this answer
no, checking that out now – datadevil Dec 15 '09 at 13:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.