
我已經用 Postfix、Roundcube 和 Dovecot 設定了一個郵件伺服器。一切都運作良好——幾乎。
在我的國家,有一種流行的免費電子郵件服務,名為 inbox.lv。他們設定了反垃圾郵件規則,當新伺服器嘗試向他們發送電子郵件時,他們首先將其列入灰名單 10 分鐘,並要求伺服器重新發送電子郵件。很公平。
但是,當使用 Postfix 發送外發電子郵件(從 Roundcube 或 Thunderbird)時,它不會將郵件排隊。相反,它會立即返回並顯示錯誤。還有一個日誌條目(為了便於閱讀,我添加了換行符/空格;出於隱私考慮,對 IP 和電子郵件地址進行了編輯):
May 31 23:17:18 21 postfix/smtpd[24814]: NOQUEUE: reject: RCPT from unknown[MY.IP.ADDRESS.HERE]:
450 4.1.1 <[email protected]>: Recipient address rejected: unverified address:
host mx1.inbox.lv[194.152.32.74] said: 450 4.7.1 <unknown[SERVER.IP.ADDRESS.HERE]>:
Client host rejected: greylisted, please retry in 597 seconds (in reply to RCPT TO command);
from=<[email protected]> to=<[email protected]> proto=ESMTP helo=<[192.168.1.216]>
所有隊列設定均保留預設值。 Postfix 版本是 2.10.1。
為什麼會發生這種情況?
添加:Postfix 設定(匿名):
[root@myserver etc]# postconf mail_version
mail_version = 2.10.1
[root@myserver etc]# postconf -n
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
command_directory = /usr/sbin
config_directory = /etc/postfix
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
debugger_command = PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin ddd $daemon_directory/$process_name $process_id & sleep 5
html_directory = no
inet_interfaces = all
inet_protocols = all
mail_owner = postfix
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
message_size_limit = 100000000
milter_default_action = accept
mydestination = localhost
mydomain = mydomain.lv
myhostname = mydomain.lv
mynetworks_style = host
myorigin = $mydomain
newaliases_path = /usr/bin/newaliases.postfix
non_smtpd_milters = $smtpd_milters
queue_directory = /var/spool/postfix
readme_directory = /usr/share/doc/postfix-2.10.1/README_FILES
sample_directory = /usr/share/doc/postfix-2.10.1/samples
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
smtpd_milters = inet:127.0.0.1:8891
smtpd_recipient_restrictions = reject_unverified_recipient
smtpd_relay_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
smtpd_sasl_auth_enable = yes
smtpd_sasl_path = private/auth
smtpd_sasl_type = dovecot
smtpd_tls_auth_only = yes
smtpd_tls_cert_file = /etc/letsencrypt/live/mydomain.lv/fullchain.pem
smtpd_tls_key_file = /etc/letsencrypt/live/mydomain.lv/privkey.pem
smtpd_tls_security_level = may
unknown_local_recipient_reject_code = 550
virtual_mailbox_domains = d1.lv d2.lv d3.lv d4.lv
virtual_mailbox_limit = 0
virtual_transport = lmtp:unix:/var/run/dovecot/lmtp
[root@myserver etc]# postconf -M
smtp inet n - n - - smtpd
submission inet n - n - - smtpd
smtps inet n - n - - smtpd
pickup unix n - n 60 1 pickup
cleanup unix n - n - 0 cleanup
qmgr unix n - n 300 1 qmgr
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
relay unix - - n - - smtp
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
[root@myserver etc]#
答案1
您將 postfix 設定為連接到遠端目標以詢問他們有關收件者的資訊 - 作為必要條件前您接受任何內容到本機佇列中。
smtpd_recipient_restrictions =
reject_unverified_recipient
在通用郵件伺服器上,這對於任何事情都是不合適的但您控制下的網域名稱或您與其運營商達成協議的網域。
詢問遠端伺服器是否有某些用戶而不發送郵件將使相當多的伺服器不再願意與您互動。在知道您要發送的內容之前,他們無法輕易判斷您是試圖清除下一個受害者名單的垃圾郵件發送者還是打算傳遞郵件的人。
解決該問題並解決您原來的問題的最簡單的更改是:
smtpd_recipient_restrictions =
permit_sasl_authenticated
,
reject_unauth_destination
, reject_unverified_recipient
因為限制是按照指定的順序處理的,所以這會免除您經過身份驗證的使用者和不相關的中繼請求(無論如何都會被拒絕)。這樣,您仍然可以強制reject_unverified_recipient
執行傳入訊息(其中 dovecot 可能會立即確認地址)。但無需在遠端伺服器上喋喋不休地詢問您尚未收到郵件的收件者。但是,如果您希望該功能也可供用戶互相寫入訊息,那麼您必須變得比這更複雜。你的 postfix 文件中的 ADDRESS_VERIFICATION_README 文件是…雖然很舊,但仍然應該給你一個總體概述。
我通常建議使用master.cf(它附帶了合適的模板,至少在最近)來設定部分分離的smtpd 實例,一個在連接埠25 上用於一般互聯網使用,另一個在連接埠465 上用於強制驗證的用戶提交。這樣,您就可以以合理可維護的方式在每個服務的基礎上實施不同的規則,進一步簡化處理與傳入流量不同的中繼流量的任務。