20

When sending mail, Postfix inserts the authenticated user’s IP and username into the Received header on the email. While this is useful for tracking down who sent a particular email that was sent from your mail server, it also has privacy implications. In a small-scale situation where I can trust all the users not to get their accounts compromised and turned into spam zombies, I’d rather not broadcast IP addresses and account names for all to read. In short, how do I set up Postfix to not send this:

Received: from [x.x.x.x] (pc1.example.com [x.x.x.x]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: user) by mail.example.com (Postfix) with ESMTPSA id CC77010C148 for ; Fri, 11 Nov 2011 04:55:18 +0000 (UTC)

3 Answers 3

27

The standard solution is to use the header_checks option. This will work, however, if we filter received lines on all mail both incoming and outgoing (as this will do), we could potentially lose Received headers on mail sent to us, which can be important for troubleshooting. To get around this problem, we will apply the header_checks only to the mail that could not possibly have been sent to us—mail that was sent to the submission port (you are using the submission port, aren’t you?).

What we need to do is pass the cleanup_service_name option to the submission service so that we can set up a new cleanup service, “subcleanup.” The relevant section of /etc/postfix/master.cf might look like this:

submission inet n       -       -       -       -       smtpd
  -o smtpd_tls_security_level=encrypt
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_client_restrictions=permit_sasl_authenticated,reject
  -o milter_macro_daemon_name=ORIGINATING
  -o cleanup_service_name=subcleanup

Now we can pass the header_checks option to the new cleanup service. That part of /etc/postfix/master.cf might look like this:

cleanup   unix  n       -       -       -       0       cleanup
subcleanup unix n       -       -       -       0       cleanup
  -o header_checks=regexp:/etc/postfix/submission_header_checks

Finally, we need to create the file /etc/postfix/submission_header_checks, which will contain the regex that filters offending Received header lines. Which regex you put in the file depends on whether you have smtpd_sasl_authenticated_header set.

If smtpd_sasl_authenticated_header is yes, then use:

/^Received:.*\(Authenticated sender:/ IGNORE

Otherwise, use:

/^Received:.*\(Postfix/ IGNORE

(Thanks to Dominic P and Bryan Drewery for showing how to handle the second case.)

7
  • Do you have to call postmap submission_header_checks?
    – Mitar
    Mar 24, 2014 at 23:29
  • @Mitar no clue, but if you find out that you do, feel free to edit the answer. These are old instructions for 10.04, but I'll probably be updating them when 14.04 comes out. Mar 25, 2014 at 0:53
  • 1
    +1, thanks for the very helpful answer. It's a few years later, and I had to make a minor tweak. I'm running Postfix 2.9.6. I changed the regex to: /^Received:.*\(Postfix/ IGNORE because I wasn't getting the "Authenticated sender" portion in my headers. Do you see any risks associated with my new regex?
    – Dominic P
    Apr 23, 2014 at 21:07
  • 1
    This answer assumes smtpd_sasl_authenticated_header=yes is set. Without it then the modified regex by Dominic is needed. May 29, 2015 at 16:05
  • 2
    Why can't you just match on ^Received:? In the submission queue there should only be one (the unwanted) Received header, shouldn't it?
    – allo
    May 10, 2020 at 17:44
1

Solving the problem of two "Received" headers from PHPLIST.

We open /etc/postfix/main.cf. Add at the end:

header_checks = regexp:/etc/postfix/header_checks

Сreate the file /etc/postfix/header_checks. We write in it:

/^Received:/ IGNORE

Finally, reload postfix

1
  • It was indeed this simple for me, thanks! Other guides tell you to change master.cf as well when this is all you need, at least if you want to filter all emails. I did run into errors after modifying main.cf first and then was creating header_checks, where postfix somehow picked up the config change and started throwing errors for emails currently being sent because header_checks didn't exist yet. Then, when it did exist, it didn't pick that up. A restart is definitely advisable after finalizing the changes, and perhaps create the header_checks file before modifying main.cf.
    – Luc
    Aug 21, 2023 at 0:22
-3

You can use

smtpd_sasl_authenticated_header = no

in postfix/main.cf to eliminate the header information in your outgoing mails.

6
  • why is this answer much simpler than @Michael's? does this remove the IP from all headers, instead of just from the mails received through the submission port?
    – knocte
    Mar 19, 2016 at 10:49
  • 2
    @knocte smtpd_sasl_authenticated_header is set to "no" by default anyway. When it is enabled, Postfix adds the username that was used for SASL authentication to the initial "Received" header — that's what adds the "Authenticated sender: user" part shown in the question. @Michael's answer removes not only the user part, but the entire "Received" header, including the client's IP.
    – n.st
    Mar 29, 2016 at 22:09
  • @n.st: are you saying that Markus' answer doesn't remove the IP and therefore doesn't this S.O. question?
    – knocte
    Mar 30, 2016 at 11:29
  • @knocte Exactly.
    – n.st
    Mar 30, 2016 at 11:37
  • 1
    I need 125+ to downvote. I've tested it and it removes the Username only, not the IP.
    – John
    Nov 25, 2016 at 17:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .