Score:1

Virtual domain variable in postfix/smtp_header_checks

es flag

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.)

Score:1
by flag

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, and it should work.

$ sudo postfix reload

Jesse יִשַׁי avatar
es flag
Vanilla Postfix at its best!
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.