我正在嘗試為一個古怪的舊語音郵件系統設定郵件中繼。我在虛擬機器上設定了 postfix,啟用了中繼,驗證了我可以從相同子網路 telnet 到連接埠 25 並將郵件發送到任何我想要的地方。這是我的 main.cf:
# See /usr/share/postfix/main.cf.dist for a commented, more complete version
# Debian specific: Specifying a file name will cause the first
# line of that file to be used as the name. The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no
# appending .domain is the MUA's job.
append_dot_mydomain = no
# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h
readme_directory = no
# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.
smtpd_helo_required = no
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = mailer
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = mailer, localhost.localdomain, localhost
relayhost =
mynetworks = 192.168.1.0/24 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_command = procmail -a "$EXTENSION"
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
不幸的是,舊的語音信箱總是在發送郵件之前嘗試發送空的 EHLO。我打開了該主機的調試,這就是我所看到的:
Oct 13 11:48:57 mailer postfix/smtpd[2201]: connect from unknown[192.168.1.98]
Oct 13 11:48:57 mailer postfix/smtpd[2201]: smtp_stream_setup: maxtime=300 enable_deadline=0
Oct 13 11:48:57 mailer postfix/smtpd[2201]: match_hostname: unknown ~? 192.168.1.0/24
Oct 13 11:48:57 mailer postfix/smtpd[2201]: match_hostaddr: 192.168.1.98 ~? 192.168.1.0/24
Oct 13 11:48:57 mailer postfix/smtpd[2201]: > unknown[192.168.1.98]: 220 mailer ESMTP Postfix (Ubuntu)
Oct 13 11:48:57 mailer postfix/smtpd[2201]: watchdog_pat: 0x7f17a114afe0
Oct 13 11:48:57 mailer postfix/smtpd[2201]: < unknown[192.168.1.98]: EHLO
Oct 13 11:48:57 mailer postfix/smtpd[2201]: > unknown[192.168.1.98]: 501 Syntax: EHLO hostname
Oct 13 11:48:57 mailer postfix/smtpd[2201]: watchdog_pat: 0x7f17a114afe0
Oct 13 11:48:58 mailer postfix/smtpd[2201]: < unknown[192.168.1.98]: HELO
Oct 13 11:48:58 mailer postfix/smtpd[2201]: > unknown[192.168.1.98]: 501 Syntax: HELO hostname
Oct 13 11:48:58 mailer postfix/smtpd[2201]: watchdog_pat: 0x7f17a114afe0
Oct 13 11:48:58 mailer postfix/smtpd[2201]: < unknown[192.168.1.98]: QUIT
Oct 13 11:48:58 mailer postfix/smtpd[2201]: > unknown[192.168.1.98]: 221 2.0.0 Bye
Oct 13 11:48:58 mailer postfix/smtpd[2201]: match_hostname: unknown ~? 192.168.1.0/24
Oct 13 11:48:58 mailer postfix/smtpd[2201]: match_hostaddr: 192.168.1.98 ~? 192.168.1.0/24
Oct 13 11:48:58 mailer postfix/smtpd[2201]: disconnect from unknown[192.168.1.98]
我對這個語音郵件系統的控制非常有限,所以讓它正常運作可能不是一個選項。有沒有辦法讓 postfix 接受任何 EHLO/HELO,即使根本沒有主機名稱?
答案1
我查看了 的原始碼smtpd
,看來目前這是不可能的。helo_cmd()
兩者ehlo_cmd()
都檢查 中至少有 2 個值argv
,其中第一個值(可能是)請求的命令 ( HELO
/ EHLO
),第二個值是主機名稱。任何額外的參數都與第二個參數連接在一起以獲得最終的主機名稱值。然後,各種配置選項控制如何驗證該值,但它必須存在。
編輯:
將其放入 postfix-users 郵件清單後,有人指出可以在處理之前將正規表示式應用於命令參數。我必須postfix-pcre
通過安裝apt-get
。然後我創建一個/etc/postfix/smtpd_cmd_filter
這樣的檔案:
# smtpd_cmd_filter
# Work around brain-dead empty EHLO
/^EHLO\s$/ EHLO domain.invalid
/^HELO\s$/ HELO domain.invalid
並將以下行加入main.cf
:
smtpd_command_filter = pcre:/etc/postfix/smtpd_cmd_filter
它不漂亮,但很有效。