要从Received标头中删除发件人IP以提交新邮件,请使用header_checks键而不是以下smtp_header_checks选项:
header_checks = regexp:/etc/postfix/header_checks_submission
该smtp_header_checks选项仅适用于从Postfix发送到外部服务器的邮件,而该header_checks选项适用于从客户端发送到Postfix的传入邮件。
另请参见http://www.postfix.org/OVERVIEW.html上Postfix的接收方式,以获取有关组件的概述,邮件来自smtpd-> cleanup->传入队列。该smtpd过程接收邮件,并在Received标题中添加发件人IP地址。该header_checks(5)选项由cleanup(8)清理电子邮件标题的组件处理。
这是不建议设置这样一个header_checks在全球范围内main.cf选择,因为这将修改接收的报头的所有电子邮件,即使是那些从外部服务器接收。相反,您应该将客户端配置为通过端口587上的专用提交服务发送电子邮件,并配置Postfix以仅重写这些经过身份验证的提交的标头。
在中/etc/postfix/master.cf,在该-o行之后添加以下submission行:
submission inet n       -       y       -       -       smtpd
  # Require SASL authentication
  -o smtpd_sasl_auth_enable=yes
  # Require TLS transport security, do not leak your credentials in plaintext.
  -o smtpd_tls_security_level=encrypt`
  # Disallow unauthenticated users from sending mail through this port.
  -o smtpd_client_restrictions=permit_sasl_authenticated,reject
  # Use a different cleanup service (see below)
  -o cleanup_service_name=ascleanup
时间配置清理服务一 uthenticated 小号 ubmissions。我选择名称ascleanup以使其简短和对齐,但是任何名称都可以。为此,请在同一文件中复制清理服务行master.cf,但重命名第一个字段并添加新选项以选择过滤器文件:
cleanup   unix  n       -       y       -       0       cleanup
ascleanup unix  n       -       y       -       0       cleanup
  -o header_checks=pcre:/etc/postfix/header_checks_submission
(使用该pcre表需要postfix-pcre在Debian上进行安装,这将自动处理更新dynamicmaps.cf文件。对此无需进行任何更改。)
最后一部分是中的实际过滤器配置/etc/postfix/header_checks_submission。您可能会使用类似:
/^Received: .*/ IGNORE
这将删除完整的Received标头行,但相反,您也可以from helo.host (reverse.host.name [192.0.2.1])在保留其他信息的同时放下零件:
/^Received: from [^ ]+ \([^ ]+ \[[IPv0-9a-f:.]+\]\)\s+(.* \(Postfix\) with .+)$/ REPLACE Received: $1
如果确实更改了该mail_name选项,请更改Postfix单词以匹配您的配置。(根据Postfix源代码smtpd / smtpd.c,此模式是准确的。)
我在Debian Buster上用postfix 3.4.7-0 + deb10u1测试了这一点。有关使用此方法的另一个详细说明,请参阅使用Postfix发送电子邮件时,如何在Received标头中隐藏发件人的IP和用户名?
通过上述修改,以下内容变为Received: by ...:
Received: from debian (unknown [IPv6:fe80::b036:2ff:fe6e:73f4])
        by mail.example.nl (Postfix) with ESMTPSA id 1571B910B
        for <some@example.com>; Sun, 12 Jan 2020 02:23:15 +0000 (UTC)