确保 postfix 不是开放中继,我尝试从我的邮件地址向我的邮件地址发送邮件,telnet 日志如下所示:
Resolving hostname...
Connecting...
SMTP -> FROM SERVER:
220 mail.example.com ESMTP Postfix
SMTP -> FROM SERVER:
250-mail.example.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
MAIL FROM: [email protected]
SMTP -> FROM SERVER:
250 2.1.0 Ok
RCPT TO: [email protected]
SMTP -> FROM SERVER:
250 2.1.5 Ok
Sending Mail Message Body...
SMTP -> FROM SERVER:
354 End data with .
SMTP -> FROM SERVER:
250 2.0.0 Ok: queued as XXXXXXXX
Message completed successfully.
我的 main.cf 上的非默认值
postconf -n
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
append_dot_mydomain = no
biff = no
config_directory = /etc/postfix
inet_interfaces = all
inet_protocols = all
lmtp_tls_mandatory_protocols = !SSLv2, !SSLv3
lmtp_tls_protocols = !SSLv2, !SSLv3
mailbox_size_limit = 0
mydestination = $myhostname, localhost.$mydomain, localhost
mydomain = example.com
myhostname = mail.$mydomain
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
myorigin = $mydomain
non_smtpd_milters = inet:127.0.0.1:8891
policy-spf_time_limit = 3600s
readme_directory = no
recipient_delimiter = +
relayhost =
smtp_generic_maps = hash:/etc/postfix/generic
smtp_tls_ciphers = medium
smtp_tls_exclude_ciphers = EXPORT, LOW, MD5, aDSS, kECDHe, kECDHr, kDHd, kDHr, SEED, IDEA, RC2
smtp_tls_loglevel = 1
smtp_tls_mandatory_protocols = !SSLv2,!SSLv3
smtp_tls_protocols = !SSLv2,!SSLv3
smtp_tls_security_level = may
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_banner = $myhostname ESMTP $mail_name
smtpd_client_connection_rate_limit = 5
smtpd_delay_reject = yes
smtpd_helo_required = yes
smtpd_milters = inet:127.0.0.1:8891
smtpd_recipient_restrictions = reject_invalid_hostname, reject_non_fqdn_hostname, reject_non_fqdn_sender, reject_non_fqdn_recipient, reject_unknown_sender_domain, reject_unauth_destination, reject_unverified_recipient, permit_mynetworks, check_recipient_access pcre:/etc/postfix/recipient_checks.pcre, check_helo_access hash:/etc/postfix/helo_checks, check_policy_service unix:private/policy-spf, reject_rbl_client cbl.abuseat.org, reject_rbl_client sbl.spamhaus.org, reject_rbl_client pbl.spamhaus.org, check_sender_access hash:/etc/postfix/check_backscatterer permit
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated reject_unauth_destination
smtpd_sasl_auth_enable = yes
smtpd_sasl_path = private/auth
smtpd_sasl_security_options = noanonymous,noplaintext
smtpd_sasl_tls_security_options = noanonymous
smtpd_sasl_type = dovecot
smtpd_sender_login_maps = hash:/etc/postfix/virtual/mailboxes
smtpd_tls_auth_only = yes
smtpd_tls_cert_file = /etc/letsencrypt/live/example.com/fullchain.pem
smtpd_tls_ciphers = medium
smtpd_tls_dh1024_param_file = ${config_directory}/dh2048.pem
smtpd_tls_eecdh_grade = strong
smtpd_tls_exclude_ciphers = EXPORT, LOW, MD5, SEED, IDEA, RC2
smtpd_tls_key_file = /etc/letsencrypt/live/example.com/privkey.pem
smtpd_tls_loglevel = 1
smtpd_tls_mandatory_ciphers = high
smtpd_tls_mandatory_protocols = !SSLv2,!SSLv3
smtpd_tls_protocols = !SSLv2,!SSLv3
smtpd_tls_security_level = may
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
tls_high_cipherlist = EDH+CAMELLIA:EDH+aRSA:EECDH+aRSA+AESGCM:EECDH+aRSA+SHA256:EECDH:+CAMELLIA128:+AES128:+SSLv3:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!DSS:!RC4:!SEED:!IDEA:!ECDSA:kEDH:CAMELLIA128-SHA:AES128-SHA
tls_ssl_options = NO_COMPRESSION
tlsproxy_tls_mandatory_protocols = $smtpd_tls_mandatory_protocols
tlsproxy_tls_protocols = $smtpd_tls_protocols
virtual_alias_maps = hash:/etc/postfix/virtual/aliases
virtual_mailbox_domains = example.com
virtual_mailbox_maps = hash:/etc/postfix/virtual/mailboxes
virtual_transport = lmtp:unix:private/dovecot-lmtp
检查邮件标头,我发现 SPF 失败:
Return-Path: <[email protected]>
Delivered-To: <[email protected]>
Received: from mail.example.com
by compute.internal (Dovecot) with LMTP id XXXXXXXXXXX
for <[email protected]>; Fri, 08 Apr 2016 01:56:03 +0000
Received-SPF: Fail (SPF fail - not authorized) identity=mailfrom; client-ip=184.72.226.23; helo=www.wormly.com; [email protected]; [email protected]
Received: from www.wormly.com (node-mec2.wormly.com [184.72.226.23])
by mail.example.com (Postfix) with ESMTP id 1234567890
for <[email protected]>; Fri, 8 Apr 2016 01:56:02 +0000 (UTC)
Date: Fri, 08 Apr 2016 01:56:03 +0000
From: [email protected]
To: [email protected]
为什么是这样? postfix 不应该在使用 smptd_recipient_restrictions 接收电子邮件之前进行检查吗?
答案1
Postfix 本身既不检查 SPF、DKIM 也不检查 DMARC。它依赖外部服务来做到这一点。在上面的配置中,SPF 检查是由侦听套接字的服务执行的private/policy-spf
。如果应在 SPF 失败时拒绝邮件,则必须在相应的策略服务中配置此行为。
此策略服务存在 Perl 和 Python 实现,因此细节可能有所不同。通过python实现,设置参数
HELO_reject = SPF_Not_Pass
Mail_From_reject = fail
in/etc/postfix-policyd-spf-python/policyd-spf.conf
应导致立即拒绝 SPF 不匹配的邮件。否则,服务将仅添加标头并接受消息。如果身份验证结果由另一个服务使用,则后一种行为可能很有用(例如,参见此骷髅的文章,描述如何设置 OpenDMARC milter)。
DKIM 身份验证器(我猜这是上面conf 中列出的milter)也必须进行配置。
另外:您的示例中并非如此,但应该注意的是,如果列出了任何收件人检查,则不会执行 SPF 策略检查前SPF 策略检查返回OK
。因此,如果要从本地主机发送邮件,则永远不会执行 SPF 检查。