Adding reply-to header for simple postfix mailing list
The Reply-To
header can be added using the smtp_header_checks
option:
smtp_header_checks = pcre:/etc/postfix/header_checks.pcre
where header_checks.pcre contains something like
/^To: [email protected]/ PREPEND Reply-To: <[email protected]>
The first part (between the slashed) is the regex matching a header. PREPEND
says that an additional line should be added to the mail. The rest is the content of the added line. If you want to experiment a little with that setup, take a look at man 5 header_checks, it explains that kind of processing in greater detail.
Rejecting messages would work similarly to the above, just add a few more rules to header_checks.pcre. It should contain something like this:
if /^To: .*<[email protected]>/
/^From: .*[email protected]/ OK
/^From: .*[email protected]/ OK
/.*/ REJECT
endif
and so on.
The above config should cause postfix to accept mail to your mailing list only if it appears to be by one of your friends. It's untested, so please proceed with care.
Related videos on Youtube
user11102206
Updated on September 18, 2022Comments
-
user11102206 almost 2 years
I have a postfix with the following in /etc/postfix/main.cf:
virtual_alias_domains = hash:/etc/postfix/mydomains virtual_alias_maps = hash:/etc/postfix/virtual
These specify the domains set up for mail forwarding, and the mail forwarding mappings.
I would like to set up a simple mailing list, which can easily be achieved by adding to the mapping file. However, I would like to add a "reply-to" header to the messages so that replies get sent back to the list rather than the original sender. I'm fairly sure this is possible with a regular expression, but I'm not quite sure where to put it.
Secondly, I wonder is it possible to make Postfix reject messages if they don't come from one of the members of the mailing list? This would be nice to have, but not essential.
The list will have about ten members, and will change very rarely, so hard coding the member addresses into regular expressions wouldn't be a big problem.
Any help would be appreciated.
-
Rui F Ribeiro over 8 yearsHave a look at Mailman
-
user11102206 over 8 yearsThanks @rui-f-ribeiro. I'm aware that mailman can easily handle mailing lists, but it is complete overkill for what I require. I think postfix should be able to handle what I need, so would like to stick with it if possible.
-
Rui F Ribeiro over 8 yearsHave a look at procmail then.
-
-
user11102206 over 8 yearsThanks a million. This is very helpful. However, messages from outside the mailing list aren't getting rejected, and I can't see any reason why not. I wonder if the regular expression isn't matching. Are there any log files I can check, or any other way to diagnose the problem?
-
tarleb over 8 yearsGlad this is useful :) I don't know about any simple ways to debug this, but now that I'm thinking about it, I realized that the
recipient_checks.pcre
will only check the RCPT TO address, not the From. Unsure if there is asimple way to fix this. I'll edit the answer. -
tarleb over 8 years@JamesShields fixed.
-
user11102206 over 8 yearsThanks again for your help here. I've got the Reply-to part working, but not the rejecting from unapproved addresses. From reading the docs, the statements within the
if
conditional can only be applied to the line matching the conditional, so you can't have anif
block on theTo
line, and match aFrom
line within that block as it would need to look at another line. Does this sound right? -
tarleb over 8 yearsD'OH! Yes, you're right, forgot about that. Thanks for the feedback, I'll test it beforehand next time.
-
BlueDogRanch over 4 yearsHi @tarleb I have the same need to add a reply to field, but have no luck with Ubuntu 19; any ideas here? askubuntu.com/questions/1201372/…