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.

  • Have a look at Mailman Dec 8, 2015 at 14:11
  • 1
    Thanks @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. Dec 8, 2015 at 14:26
  • Have a look at procmail then. Dec 8, 2015 at 14:35

1 Answer 1


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

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.

  • Thanks 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? Dec 15, 2015 at 9:23
  • Glad 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
    Dec 15, 2015 at 9:30
  • @JamesShields fixed.
    – tarleb
    Dec 15, 2015 at 9:41
  • Thanks 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 an if block on the To line, and match a From line within that block as it would need to look at another line. Does this sound right? Dec 29, 2015 at 17:14
  • D'OH! Yes, you're right, forgot about that. Thanks for the feedback, I'll test it beforehand next time.
    – tarleb
    Dec 29, 2015 at 23:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.