Centos – Adding reply-to header for simple postfix mailing list

centosemaillinuxpostfix

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.

Best Answer

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: your-mailing-list@example.net/  PREPEND Reply-To: <your-mailing-list@example.net>

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: .*<your-mailing-list@example.net>/
/^From: .*your-friend1@example.org/     OK
/^From: .*your-other-friend@exmple.net/ 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 Question