Score:0

How do I prevent postfix from adding this Reply-To header twice?

cn flag
3x5

I am running a mail server with Postfix, and I have set this line in /etc/postfix/header_checks.pcre:

/^To: [email protected]/  PREPEND Reply-To: [email protected]

[email protected] is a forwarding address. If someone sends an email to [email protected], it'll forward to a number of other addresses. However, I want the Reply-To line to be [email protected], so all replies go to everyone.

My line works, but the problem is that it's adding the 'Reply-To' header twice. I suspect the mail server is receiving the message, prepending the line, then sending out emails to each of the recipients, adding the line again. I have tried this:

if /^To: [email protected]/
!/^Reply-To: [email protected]/  PREPEND Reply-To: [email protected]
endif

The logic here is 'if this is going to [email protected], and the Reply-To header is not [email protected], then prepend the Reply-To header. The problem is, this still doesn't work. It adds the Reply-To header twice.

My understanding is that postfix header_checks can't determine whether a header is present or not, only what the content of it is. I am at a loss as to how to get this header going in only once.

Score:0
cn flag
3x5

OK, I do have a working solution for this now. In /etc/postfix/main.cf, make sure you have this line:

header_checks = pcre:/etc/postfix/header_checks.pcre

Note that this starts with header_checks and not smtp_header_checks. Then, inside this file:

/^To:.*board@example\.org/ PREPEND Reply-To: <[email protected]>
/^(Reply-To:.*)board@example\.org/ IGNORE

So there it is. If the email is going to a specific address, add the Reply-To header. Also, if the Reply-To header is already what you want, do nothing.

I don't know why it works this way, despite there being no nested condition and despite the order seeming to be incorrect, but after trying quite a lot of options, this one is working for me, consistently. I hope this helps you too.

3x5 avatar
cn flag
3x5
Sorry, I had what I thought was a solution, but it was buggy so I removed it. I just posted the fixed, correct solution.
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.