1

What Postfix virtual domain variable should I use in outgoing header creation?

Current server

I'm running a database-driven virtual domain server managed by PostfixAdmin. I want to put statements in the header of all outgoing emails using the Postfix system, not using the responsible web app or client.

We need to produce...

The question is not about a List-Unsubscribe header, which we already know should look like...

in the email header :

List-Unsubscribe: mailto:[email protected]

How we produce...

We already know to achieve that with a line tailored to outgoing checks /etc/postfix/smtp_header_checks. So, if we have this line...

main.cf :

smtp_header_checks = regexp:/etc/postfix/smtp_header_checks

(or some other setting like some_setting = regexp:/etc/postfix/some_setting?)

Then, we need in...

/etc/postfix/smtp_header_checks :

/^Content-Type:/i PREPEND List-Unsubscribe: mailto:[email protected]

But, that only works for a specific domain somedomain.tld; I need a variable that depends on the sending domain.

There are no mydomain = settings anywhere in main.cf or any other /etc/postfix/ files; all domains are managed by the virtual domain maps managed by MySQL.

So, this question is about vmail variables any sending header creation, not only List-Unsubscribe:, as long as it works in creating List-Unsubscribe: from Postfix.

(Postfix docs aren't clear about usable vmail variables in headers.)

Code with domain variable

This is my best solution: $mydomain.

/etc/postfix/smtp_header_checks :

/^Content-Type:/i PREPEND List-Unsubscribe: mailto:unsubscribe@$mydomain

When sending from a virtual domain, is $mydomain the correct way to pass that domain into header or other email content creation sent by Postfix?


(Using Postfix for this is important so that all emails will have this, even those sent from the simple CLI or by third party web apps using PHP via MSMTP, et cetera. We already know how to add it via server lang header.)

1 Answer 1

2

Postfix does not provide a built-in variable that directly corresponds to the sender's domain in smtp_header_checks, but we can use regex arguments from header_checks combined with smtp_header_checks to do the same thing.

First we use this custom header in

/etc/postfix/header_checks : add this

/^From:.*@(.*)/i PREPEND X-Sender-Domain:$1

Then prepend the List-Unsubscribe header using the custom X-Sender-Domain in

/etc/postfix/smtp_header_checks : we have

/^X-Sender-Domain:(.*)/i PREPEND List-Unsubscribe: mailto:unsubscribe@$1

Then make sure in

main.cf : we have

header_checks = regexp:/etc/postfix/header_checks
smtp_header_checks = regexp:/etc/postfix/smtp_header_checks

Then we reload with this command.

$ sudo postfix reload

1
  • Vanilla Postfix at its best!
    – Jesse
    Commented Apr 30, 2023 at 14:36

You must log in to answer this question.

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