what the best way to use specific transport on specific header detection ?

LeFred

Member
May 18, 2022
23
4
8
Hello community,

I have this case :
  • PMG-BO acting as a smarthost for all the intranet
  • PMG-FO acting as a default relay for outgoing mails
  • PMG-FO-OTP with specific config to send OTP codes (maximal_queue_lifetime=30m ; IP dedicated, and so on...)
The question : what would be the best way to route mails with specific headers for OTP (ie. X-OTP-code: true) to PMG-FO-OTP in the smarhost PMG-BO ?

Thanx for your contributions.
 
Hello, @LeFred
Seems like you can use a method similar to one described at

https://chase-seibert.github.io/blog/2005/10/19/postifx-header-based-routing.html

"First, enable header checks in /etc/postfix/main.cf:

header_checks = regexp:/etc/postfix/header_checks

Then, insert a new header check in /etc/postfix/header_checks:

/^X-Smarthost: (.*)$/ FILTER smtp:$1

This will use a regex to match any email with a "X-Smarthost:" token in the header, and save the substring in the parenthesis to $1, which you can conveniently pass to the smtp transport. Any email not matching this rule will go through the default transport, which in a clean install means regular old DNS + smtp."

The bloger uses the original Postfix' main.cf, but in Proxmox Mail Gateway you should use "templates", so that the config isn't overwritten by updates, it's described in the PMG docs:

https://pmg.proxmox.com/pmg-docs/pmg-admin-guide.html#pmgconfig_template_engine

Also, he uses X-Smarthost header, while you'll need X-OTP-code: true, of course. You probably won't need the $1, just a static transport.

You can use regexp: or pcre: patterns for matching.

The detailed docs on header_checks are at https://www.postfix.org/header_checks.5.html
 
Last edited:
  • Like
Reactions: LeFred
Ouch !
I use PMG templates

If I just activate header_checks in /etc/pmg/templates/main.cf.in
and add /^X-OTP-code: true/ FILTER smtp:[192.168.10.10] in /etc/pmg/templates/header_checks (+ postfix restart)
it doesn't seem to take effect... the mail injected by internal port (26) is relayed to 127.0.0.1:10023, relayed to 127.0.0.1:10024 and finally removed from queue. Never see relay=192.168.10.10.

So, I modified header_checks : /^X-OTP-code: true/ FILTER smtpOTP:[192.168.10.10]
And add this service in /etc/pmg/templates/master.cf.in : smtpOTP unix - - - - - smtp
(+ postfix restart)
but, again, the mail isn't send to 192.168.10.10... same way 10023>10024>removed. Never relay=192.168.10.10.

what am I missing ?...
 
Last edited:
oh yes of course, post is corrected- (thanx) - edit : I forgot to save the correction this morning...
 
Last edited: