2

I have 4 servers. prod1.example.com, prod2.example.com, dev1.example.com, and dev2.example.com. They all send their mails to smtp.example.com. This server does the relay. Now I want that dev1 and dev2 send all their e-mails to [email protected] except for the e-mails that are sent to [email protected]. The e-mails from prod1 and prod2 are relayed without any restriction.

I read that in the access file you can define that a server must be handled by a filter instead of a simple RELAY (with FILTER foo:bar). I cannot find how and where I need to define this foo (transport) and bar (destination). Al these different parameters confuse me. Also in what order are the different files handled?

Can anybody help me out?

2 Answers 2

1

Your question can be expressed by this pseudocode

if (client == dev1 OR client == dev2)
    if recipient == admin
        pass it
    else
        redirect to devbox
else
    pass it

Unfortunately, postfix doesn't have generic language (example vcl for varnish configuration) for handle the restriction and forwarding. So, we can try to solve it with hash table feature from postfix. I have two idea how to solve this problem.

Multiple ports solution

I assume, (by default) your dev and prod servers connect to smtp.example.com with same port (port 25). If you can modify the code and adjust firewall restriction, so dev1 and dev2 should connect to smtp.example.com with different port than 25(for example port 2525), then you can go with simple solution. If this scenario doesn't possible, you can skip this idea and go to solution 2.

To allow dev server connect to postfix via port 2525, set another smtpd instance with add this line in master.cf

2525       inet  n       -       n       -       -       smtpd -o smtpd_client_restrictions=check_recipient_access,pcre:/etc/postfix/devbox

Now, the content of /etc/postfix/devbox

/admin@example\.com/    OK
/devbox@example\.com/   OK
/.*/                   REDIRECT [email protected]

Now, the prod server won't get the filter like above because they are connect to postfix via port 25. So, it can go through postfix like before.

Restriction Classes Solution

If scenario like first idea wasn't possible, then you can achieve it with restriction class. To do this you can use postfix feature called restriction classes. See

In main.cf add this line

smtpd_restriction_classes = devbox
devbox = check_recipient_access pcre:/etc/postfix/devbox
smtpd_recipient_restrictions = 
    ...
    check_client_access hash:/etc/postfix/emailrouting,
    ...

Content of /etc/postfix/emailrouting

dev1.example.com    devbox
dev2.example.com    devbox

Content of /etc/postfix/devbox

/admin@example\.com/    OK
/devbox@example\.com/   OK
/.*/                   REDIRECT [email protected]
9
  • Many thanks for your reply. I have been looking that way but I could not find out which parameters to use. Your first option would be possible but I prefer not to change the ports on the different servers. I have seen a way to relay the mails to a different port on the same server but was not able to do so. Monday I will try to implement the second option. Looks easier to maintain and to extend with other groups of servers. All is done in postfix itself.
    – Marco
    Dec 20, 2014 at 13:48
  • It works. I did the modifications as you said the redirection worked. I even added a tstbox the same way. Many thanks for the solution.
    – Marco
    Dec 22, 2014 at 10:06
  • When I restart postfix I get error: postconf: warning: /etc/postfix/master.cf: unused parameter: smtpd_client_restriction=check What is wrong? Mar 3, 2015 at 14:34
  • Hi @ServerFault, sorry for the wrong solution. Looks like you have pointed that my first idea wasn't applicable :(. Please use "Restriction Classes Solution"
    – masegaloeh
    Mar 3, 2015 at 21:16
  • Ok thank you for taking time to fix your answer. I will implement Restriction Classes Solution. Mar 3, 2015 at 21:42
1

I am no expert on this but I have been messing with Postfix myself recently and may be able to at least push you in the right direction.

With postfix you can use aliases and map say one address or a bunch of addresses to another. What you will likely want is the recipient_canonical mapping:

http://www.postfix.org/ADDRESS_REWRITING_README.html#canonical

Granted using this method means you would have to put all possible address into the file to ensure emails to any address other than [email protected] get sent to [email protected], but with the mapping you can use Regex.

https://superuser.com/questions/353488/regex-multiple-catch-all-setup-in-postfix

My suggestions would be to ask on Stackoverflow for a simple regex to check if the address is NOT equal to [email protected] then send to [email protected]. This would mean that all other addresses would pass this check and therefore go to [email protected], whereas [email protected] would fail and therefore simply be sent to the intended address.

Hopefully this may give you a nudge in the right direction, any questions you have I will answer to the best of my knowledge.

2
  • Thanks for the information. Rewriting the address is just part of the problem. I already had this working but in my configuration. It rewrites for all servers. I need to rewrite the addresses based on the server that sends them. If I look at the other reply to my question then for the rewriting postfix stops searching when an e-mail address fits the rule. A generic rewrite at the end does the tick that we need.
    – Marco
    Dec 20, 2014 at 14:35
  • @marco good to know you are closer to solving your issue. Masegaloeh seems to be the man. I definitely learned something from his answer also Dec 21, 2014 at 20:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .