![Postfix header_checks 不起作用](https://linux22.com/image/671835/Postfix%20header_checks%20%E4%B8%8D%E8%B5%B7%E4%BD%9C%E7%94%A8.png)
我只是想不明白为什么 header_checks 没有被评估。
我在 /etc/postfix/main.cf 中添加了以下行:
header_checks = pcre:/etc/postfix/header_checks.pcre
这是 header_checks.pcre :
/^From: [email protected]/ REDIRECT [email protected]
为了测试它我尝试了:
postmap -q "From: [email protected]" pcre:/etc/postfix/header_checks.pcre
其计算结果正确并返回输出:
REDIRECT [email protected]
但当我收到来自[电子邮件保护]这不起作用。我的邮件日志显示:
Nov 26 07:30:11 smtp postfix/smtpd[18733]: connect from gatekeeper.pressclip.si[213.161.20.180]
Nov 26 07:30:19 smtp sqlgrey: grey: domain awl match: updating 213.161.20(213.161.20.180), pressclip.si
Nov 26 07:30:19 smtp postfix/smtpd[18733]: 0F1862111E: client=gatekeeper.pressclip.si[213.161.20.180]
Nov 26 07:30:19 smtp sqlgrey: grey: domain awl match: updating 213.161.20(213.161.20.180), pressclip.si
Nov 26 07:30:19 smtp sqlgrey: grey: domain awl match: updating 213.161.20(213.161.20.180), pressclip.si
Nov 26 07:30:19 smtp sqlgrey: grey: domain awl match: updating 213.161.20(213.161.20.180), pressclip.si
Nov 26 07:30:19 smtp sqlgrey: grey: domain awl match: updating 213.161.20(213.161.20.180), pressclip.si
Nov 26 07:30:19 smtp sqlgrey: grey: domain awl match: updating 213.161.20(213.161.20.180), pressclip.si
Nov 26 07:30:19 smtp sqlgrey: grey: domain awl match: updating 213.161.20(213.161.20.180), pressclip.si
Nov 26 07:30:19 smtp sqlgrey: grey: domain awl match: updating 213.161.20(213.161.20.180), pressclip.si
Nov 26 07:30:19 smtp sqlgrey: grey: domain awl match: updating 213.161.20(213.161.20.180), pressclip.si
Nov 26 07:30:19 smtp sqlgrey: grey: domain awl match: updating 213.161.20(213.161.20.180), pressclip.si
Nov 26 07:30:19 smtp sqlgrey: grey: domain awl match: updating 213.161.20(213.161.20.180), pressclip.si
Nov 26 07:30:19 smtp sqlgrey: grey: domain awl match: updating 213.161.20(213.161.20.180), pressclip.si
Nov 26 07:30:19 smtp postfix/cleanup[18828]: 0F1862111E: message-id=<[email protected]>
Nov 26 07:30:21 smtp postfix/qmgr[14986]: 0F1862111E: from=<[email protected]>, size=4125270, nrcpt=12 (queue active)
Nov 26 07:30:21 smtp postfix/smtpd[18733]: disconnect from gatekeeper.pressclip.si[213.161.20.180]
Nov 26 07:30:21 smtp postfix/cleanup[18827]: 09F6A212AB: message-id=<[email protected]>
Nov 26 07:30:21 smtp postfix/qmgr[14986]: 09F6A212AB: from=<[email protected]>, size=4125593, nrcpt=12 (queue active)
Postconf -n
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
anvil_rate_time_unit = 600s
body_checks = regexp:/etc/postfix/body_checks
command_directory = /usr/sbin
config_directory = /etc/postfix
content_filter = smtp:[127.0.0.1]:2526
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
header_checks = pcre:/etc/postfix/header_checks.pcre
html_directory = no
inet_interfaces = all
inet_protocols = ipv4
luser_relay = [email protected]
mail_owner = postfix
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
message_size_limit = 30971520
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
mydomain = ztm.si
myhostname = ip04.ztm.si
mynetworks = 193.2.210.0/24, 92.244.66.224/28, 127.0.0.0/8, 89.212.169.201/32, 10.0.0.0/8 172.31.255.0/24
myorigin = $myhostname
newaliases_path = /usr/bin/newaliases.postfix
queue_directory = /var/spool/postfix
readme_directory = /usr/share/doc/postfix-2.6.6/README_FILES
relay_domains = $mydestination
sample_directory = /usr/share/doc/postfix-2.6.6/samples
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
smtp_starttls_timeout = 100s
smtp_tls_loglevel = 3
smtp_tls_mandatory_protocols = !SSLv2, !SSLv3
smtp_tls_note_starttls_offer = yes
smtp_tls_security_level = may
smtpd_client_connection_count_limit = 10
smtpd_client_connection_rate_limit = 300
smtpd_client_message_rate_limit = 300
smtpd_client_recipient_rate_limit = 300
smtpd_recipient_restrictions = permit_mynetworks reject_unauth_destination check_policy_service inet:127.0.0.1:2501
smtpd_starttls_timeout = 100s
smtpd_tls_CAfile = /etc/postfix/DigiCertCA.crt
smtpd_tls_cert_file = /etc/postfix/smtp_ztm_si.crt
smtpd_tls_key_file = /etc/postfix/smtp.key
smtpd_tls_loglevel = 3
smtpd_tls_security_level = may
transport_maps = hash:/etc/postfix/transport
unknown_local_recipient_reject_code = 550
virtual_alias_maps = hash:/etc/postfix/virtual_alias_map
主控文件
smtp inet n - n - - smtpd
submission inet n - n - - smtpd
-o smtpd_sasl_auth_enable=yes
-o smtpd_sasl_security_options=noanonymous
-o broken_sasl_auth_clients=yes
-o smtpd_client_restrictions=permit_sasl_authenticated,reject
-o smtpd_recipient_restrictions=permit_sasl_authenticated,reject
-o smtpd_tls_key_file=/etc/postfix/smtp.key
-o smtpd_tls_cert_file=/etc/postfix/smtp_ztm_si.crt
-o smtpd_tls_CAfile=/etc/postfix/DigiCertCA.crt
-o content_filter=
-o smtpd_use_tls=yes
# -o smtpd_enforce_tls=yes
smtps inet n - n - - smtpd
-o smtpd_tls_wrappermode=yes
-o smtpd_sasl_auth_enable=yes
-o smtpd_client_restrictions=permit_sasl_authenticated,reject
-o smtpd_sasl_security_options=noanonymous
-o broken_sasl_auth_clients=yes
-o smtpd_etrn_restrictions=reject
-o smtpd_recipient_restrictions=permit_sasl_authenticated,reject
-o smtpd_tls_key_file=/etc/postfix/smtp.key
-o smtpd_tls_cert_file=/etc/postfix/smtp_ztm_si.crt
-o smtpd_tls_CAfile=/etc/postfix/DigiCertCA.crt
-o smtpd_use_tls=yes
-o smtpd_enforce_tls=yes
-o content_filter=
# -o content_filter=smtp:localhost:2525
#submission inet n - 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
#smtps inet n - n - - smtpd
# -o smtpd_tls_wrappermode=yes
# -o smtpd_sasl_auth_enable=yes
# -o smtpd_client_restrictions=permit_sasl_authenticated,reject
# -o milter_macro_daemon_name=ORIGINATING
#628 inet n - n - - qmqpd
pickup fifo n - n 60 1 pickup
cleanup unix n - n - 0 cleanup
qmgr fifo n - n 300 1 qmgr
#qmgr fifo n - n 300 1 oqmgr
tlsmgr unix - - n 1000? 1 tlsmgr
rewrite unix - - n - - trivial-rewrite
bounce unix - - n - 0 bounce
defer unix - - n - 0 bounce
trace unix - - n - 0 bounce
verify unix - - n - 1 verify
flush unix n - n 1000? 0 flush
proxymap unix - - n - - proxymap
proxywrite unix - - n - 1 proxymap
smtp unix - - n - - smtp
# When relaying mail as backup MX, disable fallback_relay to avoid MX loops
relay unix - - n - - smtp
-o smtp_fallback_relay=
# -o smtp_helo_timeout=5 -o smtp_connect_timeout=5
showq unix n - n - - showq
error unix - - n - - error
retry unix - - n - - error
discard unix - - n - - discard
local unix - n n - - local
virtual unix - n n - - virtual
lmtp unix - - n - - lmtp
anvil unix - - n - 1 anvil
scache unix - - n - 1 scache
smtp-esets unix - - n - 6 lmtp
-o lmtp_data_done_timeout=1200
-o lmtp_send_xforward_command=yes
-o disable_dns_lookups=yes
-o max_use=20
localhost:2525 inet n - n - - smtpd
-o content_filter=
-o myhostname=esets.ztm.si
-o local_recipient_maps=
-o relay_recipient_maps=
-o receive_override_options=no_unknown_recipient_checks,no_header_body_checks
-o smtpd_helo_restrictions=
-o smtpd_client_restrictions=
-o smtpd_sender_restrictions=
-o smtpd_recipient_restrictions=permit_mynetworks,reject
-o mynetworks=127.0.0.0/8
有什么想法吗?谢谢!
答案1
一个问题可能是receive_override_options=no_header_body_checks
在main.cf
或中某个地方master.cf
关闭了标头检查。在master.cf
文件中,它将是-o
其中一个服务配置条目中的一个选项。
有 4 个选项receive_override_options
:
- no_unknown_recipient_checks 不尝试拒绝未知收件人(仅限 SMTP 服务器)。这通常在外部内容过滤器之后指定。
- no_address_mappings 禁用规范地址映射、虚拟别名映射扩展、地址伪装和自动 BCC(密件抄送)收件人。这通常在外部内容过滤器之前指定。
- no_header_body_checks 禁用 header/body_checks。这通常在外部内容过滤器之后指定。
- no_milters 禁用 Milter(邮件过滤器)应用程序。这通常在外部内容过滤器之后指定。
这些no_address_mappings
选项通常位于,main.cf
而其他选项位于master.cf
“-o accept_override_options” 会覆盖 main.cf 设置,以避免重复内容过滤器之前已经完成的工作。这些选项是对 main.cf 中指定的选项的补充
答案2
作为@HZC说这可能是-o 接收覆盖选项问题。我在这里遇到了同样的问题:我的问题并按照帖子解决了这个问题postfix header_checks 使用 regexp 正确设置。我的情况是拒绝反而丢弃。如果你想欺骗垃圾邮件发送者,则使用 DISCARD,垃圾邮件发送者将不会收到任何通知。有关此内容的更多信息,请访问此链接并看到拒绝行动部分。
丢弃结构:
DISCARD optional text...
Claim successful delivery and silently discard the message. Log
the optional text if specified, otherwise log a generic message.
答案3
我遇到了与 postfix 相同或类似的问题(似乎)没有评估 header_checks。我还曾经postmap -q
验证过正则表达式是否被触发,并且这有效(在我的情况下是“Subject”标头)。
然而,当我在客户端检查电子邮件标题和原始文本时(我使用的是 mutt,因此标题由 打开h
,并使用 保存原始电子邮件|
),我发现特定的逃避电子邮件消息的主题行格式不正确,即包含换行符并且采用 utf-8 编码。(这在电子邮件客户端的漂亮打印中看不到。)
调整换行符的正则表达式为我解决了这个问题。(目前是一个黑客;我猜 header_checks 引擎应该将输入解释为一个逻辑行)
一些进一步的提示:
使用以下命令检查已保存的原始邮件的正则表达式是否有效
cat my_test_mail | postmap -h -q - regexp:/etc/postfix/header_checks.regexp
使用检查邮件的十六进制内容
hexdump -C
。postmap 似乎对以下键进行检查:未解码原始电子邮件文本。