I have some development and test servers, that are only used for internal testing and development, but they often use setup from live solutions, including email addresses of customers and customers customers.

I would like to avoid the dev-solutions sending emails to customers, but allow them to send emails to developers, so that they can test the email part of the solution. I have tried a header_checks rule like this:

/^To:.*@(myowndomaion.com|myotherdomain.com|athirddomain.net)/ DUNNO /^To:.*@/ REDIRECT mytestemail@myowndomain.com

And this works fine. If I send an email to test@gmail.com it will be forwarded to mytestemail@myowndomain.com and not be sent to test@gmail.com . But if I however send an email to myuser@myowndomain.com it will be send straight to the correct user. That is all fine.

The problem arises if I send emails to several email addresses!

So, if I send an email to test@gmail.com and myuser@myowndomain.com in the same email, they will both get the email (which they should not). The order does not matter, both will get emails in both cases.

So, does anyone have a better regex or some other better way to solve this?

Note: We use Postfix on Debian. (pretty standard Debian 6 and Debian 8)