2

I'm looking for a postfix configuration to create recipient rewrite rules based on the recipient domain name including catch all for domains not found in the "not rewrite"-list. For example:

  • laber@example.com, no rewrite and deliver to MX of example.com
  • foo@bar.com, rewrite to foo@spam.example.com
  • <user>@<domain>, rewrite to <user>@spam.example.com

Ideal would be a list of domains which should not be rewritten via Postfix. For now I using a setup without the exception so everything is rewritten:

recipient_canonical_maps = static:@spam.example.com

user4336901
  • 31
  • 1
  • 3

2 Answers2

1

In main.cf add (removing the existing static map):

recipient_canonical_maps = pcre:/etc/postfix/rcpt_canonical_maps

In /etc/postfix/rcpt_canonical_maps(replace domain1.com etc with your 'good' domains):

if !/^(.*)@(domain1.com|domain2.com|domain3.com)$/
/^(.*)@.*$/ REDIRECT ${1}@spam.example.com
endif

Please not, i have not tested this, but I'm fairly confident this will do what you require.

Having said that I should stress that it's important to test this in a non-production environment.

Aaron Tate
  • 1,222
  • 7
  • 9
1

Thank you Aaron, your answer helped me a lot. I could confirm the following settings works with my current running postfix setup (stable Ubuntu 14.04).

I've added the following to main.cf:

# Receive all emails and rewrite the destination because of testing.
recipient_canonical_maps = regexp:/etc/postfix/recipient_canonical_maps

My recipient_canonical_maps looks like the following:

!/.*@example.com/ @spam.example.com
user4336901
  • 31
  • 1
  • 3