0

We have an SMTP relay (postfix) where we need to rewrite headers on the fly based on certain criteria:

if> header contains x-custom-header: type 1
and if> to: @customer1.com
rewrite> from: <[email protected]> to from: Friendly Name <[email protected]>

Currently I'm using 3 instances of postmulti just for once client, with a header_check for each component of the ruleset.

But this approach will spawn / require a new instance for each rule due to restrictions in postfix where you can't have a header check for both a TO and FROM field in the same rule.

Question is: how do I scale this in an effective manner? Is there a better way to format / utilize the header checks.

Or are there alternative systems to easily manage advanced rulesets for header rewrites in an SMTP relay, like maybe through a gui?

Requirements will be to have multiple rules for at least three x-custom-headers with multiple clients.

Postfix Config: Instance 1

#main.cf instance 1:
...
header_checks = pcre:/etc/postfix/header_checks
multi_instance_wrapper = ${command_directory}/postmulti -p --
multi_instance_enable = yes
multi_instance_directories = /etc/postfix-instance2 /etc/postfix-instance3
...
#header_checks instance 1
/^x-custom-header: type 1/ FILTER smtp:127.0.0.1:10025
#need to add this next /^x-custom-header: type 2/ FILTER smtp:127.0.0.1:10026
#need to add this next /^x-custom-header: type 3/ FILTER smtp:127.0.0.1:10027

Instance 2

#master.cf instance 2
127.0.0.1:10025      inet  n       -       n       -       -       smtpd
#main.cf instance 2
...
queue_directory = /var/spool/postfix-instance2
data_directory = /var/lib/postfix-instance2
header_checks = pcre:/etc/postfix-instance2/header_checks
multi_instance_name = postfix-instance2
multi_instance_enable = yes
...
#header_checks instance 2
/^To: (.*)@customer1.com/ FILTER smtp:127.0.0.1:10028

Instance 3

#master.cf instance 3
127.0.0.1:10028      inet  n       -       n       -       -       smtpd
#main.cf instance 3
...
queue_directory = /var/spool/postfix-instance3
data_directory = /var/lib/postfix-instance3
header_checks = pcre:/etc/postfix-instance3/header_checks
multi_instance_name = postfix-instance3
multi_instance_enable = yes
...
#header_checks instance 3
^From: (.*?)@mycompany.com/ REPLACE From: Friendly Name <[email protected]>
1
  • Do you have any examples on how you would use that for the scenario described? The milter documentation is a bit of a heavy read and haven't encountered that before..
    – SysadminB
    Jul 23, 2019 at 14:09

1 Answer 1

0

I took a different approach using postfix pipe to a script as suggested in some of these resources:

and just because I ran into this issue trying to avoid a loop:

For my default-postfix's master.cf

external unix - n n - - pipe flags=Fq user=mail null_sender= argv=/opt/scripts/external.sh ${recipient} ${domain} ${sender}

Second instance's main.cf I had to add authorized_submit_users = mailuser and in master.cf I'm listening on a separate port 127.0.0.1:10025 inet n - n - - smtpd

Then I'm still busy writing the logic for the bash script, but I think I will use the same approach as this post, but nost notably is the sendmail command to use the second instance /usr/sbin/sendmail -G -i -t -C /etc/postfix-sender/main.cf

You must log in to answer this question.

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