我目前正在嘗試使用 postfix、dovecot、amavis、sqlite 等設定郵件伺服器。
假設我有:mydomain.com 和 mail.mydomain.com(此處為 MX 記錄點)
當發送電子郵件到外部郵件地址時(比方說[電子郵件受保護]),postfix 嘗試在虛擬郵件資料庫中尋找該電子郵件。 (在設定虛擬郵件系統之前,我可以透過mail命令發送郵件。)
/var/log/mail.log:
Sep 12 12:34:11 mail postfix/submission/smtpd[7695]: initializing the server-side TLS engine
Sep 12 12:34:11 mail postfix/submission/smtpd[7695]: connect from unknown[myhomeip]
Sep 12 12:34:12 mail postfix/submission/smtpd[7695]: setting up TLS connection from unknown[myhomeip]
Sep 12 12:34:12 mail postfix/submission/smtpd[7695]: unknown[myhomeip]: TLS cipher list "aNULL:-aNULL:HIGH:MEDIUM:+RC4:@STRENGTH:!aNULL:!LOW:!EXP:!MEDIUM:!ADH:!AECDH:!MD5:!DSS:!ECDSA:!3DES:!DES:!eNULL:!RC4:!CBC3-SHA:!PSK"
Sep 12 12:34:12 mail postfix/submission/smtpd[7695]: SSL_accept:before SSL initialization
Sep 12 12:34:12 mail postfix/submission/smtpd[7695]: SSL_accept:before SSL initialization
Sep 12 12:34:12 mail postfix/submission/smtpd[7695]: unknown[myhomeip]: Decrypting session ticket, key expiration: 1631442310
Sep 12 12:34:12 mail postfix/submission/smtpd[7695]: SSL_accept:SSLv3/TLS read client hello
Sep 12 12:34:12 mail postfix/submission/smtpd[7695]: SSL_accept:SSLv3/TLS write server hello
Sep 12 12:34:12 mail postfix/submission/smtpd[7695]: SSL_accept:SSLv3/TLS write change cipher spec
Sep 12 12:34:12 mail postfix/submission/smtpd[7695]: SSL_accept:TLSv1.3 write encrypted extensions
Sep 12 12:34:12 mail postfix/submission/smtpd[7695]: SSL_accept:SSLv3/TLS write finished
Sep 12 12:34:12 mail postfix/submission/smtpd[7695]: SSL_accept:TLSv1.3 early data
Sep 12 12:34:12 mail postfix/submission/smtpd[7695]: SSL_accept:TLSv1.3 early data
Sep 12 12:34:12 mail postfix/submission/smtpd[7695]: SSL_accept:SSLv3/TLS read finished
Sep 12 12:34:12 mail postfix/submission/smtpd[7695]: unknown[myhomeip]: Reusing old session (RFC 5077 session ticket)
Sep 12 12:34:12 mail postfix/submission/smtpd[7695]: Anonymous TLS connection established from unknown[myhomeip]: TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)
Sep 12 12:34:12 mail postfix/submission/smtpd[7695]: 502B781E4E: client=unknown[myhomeip], sasl_method=PLAIN, [email protected]
Sep 12 12:34:12 mail postfix/cleanup[7700]: 502B781E4E: message-id=<[email protected]>
Sep 12 12:34:12 mail postfix/qmgr[6826]: 502B781E4E: from=<[email protected]>, size=330, nrcpt=1 (queue active)
Sep 12 12:34:12 mail postfix/submission/smtpd[7695]: disconnect from unknown[myhomeip] ehlo=2 starttls=1 auth=1 mail=1 rcpt=1 data=1 commands=7
Sep 12 12:34:12 mail dovecot: imap([email protected])<7250><x83QYcnLPEhehlnC>: Connection closed (noop finished 0.207 secs ago) in=1695 out=5945 deleted=0 expunged=0 trashed=0 hdr_count=1 hdr_bytes=241 body_count=0 body_bytes=0
Sep 12 12:34:12 mail postfix/smtpd[7704]: initializing the server-side TLS engine
Sep 12 12:34:12 mail postfix/smtpd[7704]: connect from localhost[127.0.0.1]
Sep 12 12:34:12 mail postfix/smtpd[7704]: B4A9F81E73: client=localhost[127.0.0.1]
Sep 12 12:34:12 mail postfix/cleanup[7700]: B4A9F81E73: message-id=<[email protected]>
Sep 12 12:34:12 mail postfix/qmgr[6826]: B4A9F81E73: from=<[email protected]>, size=780, nrcpt=1 (queue active)
Sep 12 12:34:12 mail postfix/smtpd[7704]: disconnect from localhost[127.0.0.1] ehlo=1 mail=1 rcpt=1 data=1 quit=1 commands=5
Sep 12 12:34:12 mail amavis[847]: (00847-08) Passed CLEAN {RelayedOpenRelay}, [myhomeip]:18412 [myhomeip] <[email protected]> -> <[email protected]>, Queue-ID: 502B781E4E, Message-ID: <[email protected]>, mail_id: thEgZdv5F-0T, Hits: 0.688, size: 330, queued_as: B4A9F81E73, 327 ms
Sep 12 12:34:12 mail postfix/lmtp[7701]: 502B781E4E: to=<[email protected]>, relay=127.0.0.1[127.0.0.1]:10024, delay=0.5, delays=0.14/0.01/0.01/0.34, dsn=2.0.0, status=sent (250 2.0.0 from MTA(smtp:[127.0.0.1]:10025): 250 2.0.0 Ok: queued as B4A9F81E73)
Sep 12 12:34:12 mail postfix/qmgr[6826]: 502B781E4E: removed
Sep 12 12:34:12 mail postfix/virtual[7705]: B4A9F81E73: to=<[email protected]>, relay=virtual, delay=0.06, delays=0/0.03/0/0.02, dsn=5.1.1, status=bounced (unknown user: "[email protected]")
Sep 12 12:34:12 mail postfix/cleanup[7700]: C2D3C81E74: message-id=<[email protected]>
Sep 12 12:34:12 mail postfix/qmgr[6826]: C2D3C81E74: from=<>, size=2692, nrcpt=1 (queue active)
Sep 12 12:34:12 mail postfix/bounce[7706]: B4A9F81E73: sender non-delivery notification: C2D3C81E74
Sep 12 12:34:12 mail postfix/qmgr[6826]: B4A9F81E73: removed
Sep 12 12:34:12 mail postfix/virtual[7705]: C2D3C81E74: to=<[email protected]>, relay=virtual, delay=0.01, delays=0/0/0/0, dsn=2.0.0, status=sent (delivered to maildir)
Sep 12 12:34:12 mail postfix/qmgr[6826]: C2D3C81E74: removed
Sep 12 12:34:19 mail dovecot: imap-login: Login: user=<[email protected]>, method=PLAIN, rip=myhomeip, lip=myserverip, mpid=7712, TLS, session=<B00g5MnL7kdehlnC>
請注意第 33 行中的 status=bounced Unknown user。未知用戶: ”[電子郵件受保護]」
我可以接收外部電子郵件,如果我從我的網域發送電子郵件到我的網域,我也可以接收/發送電子郵件。
我的主機名稱是 mail.mydomain.com
我的主機檔案:
127.0.0.1 localhost
127.0.1.1 mail.mydomain.com
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
myserverip mydomain.com
SQL傳輸內容:
sqlite> SELECT * FROM transports;
mydomain.com|1001|virtual:
postconf -n 的輸出:
append_dot_mydomain = no
biff = no
compatibility_level = 2
content_filter = lmtp-amavis:[127.0.0.1]:10024
inet_interfaces = all
inet_protocols = ipv4
local_recipient_maps =
mailbox_size_limit = 1024
masquerade_domains = $mydomain
mydestination = $mydomain, $myhostname, localhost.mydomain.com, localhost
myhostname = mail.mydomain.com
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
myorigin = /etc/mailname
readme_directory = no
recipient_delimiter = +
relayhost =
smtp_tls_exclude_ciphers = LOW, EXP
smtp_tls_loglevel = 2
smtp_tls_mandatory_protocols = !SSLv2, !SSLv3, !TLSv1, !TLSv1.1
smtp_tls_protocols = !SSLv2, !SSLv3, !TLSv1, !TLSv1.1
smtp_tls_security_level = may
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
smtpd_recipient_restrictions = reject_unknown_client_hostname
smtpd_relay_restrictions = permit_mynetworks,permit_sasl_authenticated,defer_unauth_destination
smtpd_tls_auth_only = yes
smtpd_tls_cert_file = /etc/letsencrypt/live/mail.mydomain.com/fullchain.pem
smtpd_tls_dh1024_param_file = /etc/letsencrypt/dhparams.pem
smtpd_tls_exclude_ciphers = aNULL, LOW, EXP, MEDIUM, ADH, AECDH, MD5, DSS, ECDSA, 3DES, DES, eNULL, RC4, CBC3-SHA, PSK
smtpd_tls_key_file = /etc/letsencrypt/live/mail.mydomain.com/privkey.pem
smtpd_tls_loglevel = 2
smtpd_tls_mandatory_protocols = !SSLv2, !SSLv3, !TLSv1, !TLSv1.1
smtpd_tls_protocols = !SSLv2, !SSLv3, !TLSv1, !TLSv1.1
smtpd_tls_received_header = yes
smtpd_tls_security_level = may
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
tls_preempt_cipherlist = yes
tls_ssl_options = NO_RENEGOTIATION
transport_maps = sqlite:/etc/postfix/sqlite_transports_maps.cf
virtual_alias_maps = sqlite:/etc/postfix/sqlite_virtual_alias_maps.cf
virtual_gid_maps = static:1001
virtual_mailbox_base = /home/mail/
virtual_mailbox_maps = sqlite:/etc/postfix/sqlite_virtual_mailbox_maps.cf
virtual_uid_maps = static:1001
/etc/mailname 包含 mydomain.com
master.cf的內容:
smtp inet n - y - - smtpd
submission inet n - y - - smtpd
-o syslog_name=postfix/submission
-o smtpd_tls_wrappermode=no
-o smtpd_tls_security_level=encrypt
-o smtpd_sasl_auth_enable=yes
-o smtpd_tls_auth_only=yes
-o smtpd_relay_restrictions=permit_mynetworks,permit_sasl_authenticated,reject
-o smtpd_sasl_type=dovecot
-o smtpd_sasl_path=private/auth
-o smtpd_recipient_restrictions=
smtps inet n - y - - smtpd
-o syslog_name=postfix/smtps
-o smtpd_sasl_auth_enable=yes
-o smtpd_tls_auth_only=yes
-o smtpd_tls_wrappermode=yes
lmtp-amavis unix - - - - 2 lmtp
-o lmtp_data_done_timeout=1200
-o lmtp_send_xforward_command=yes
-o max_use=20
127.0.0.1:10025 inet n - n - - smtpd
-o content_filter=
-o mynetworks=127.0.0.0/8
-o smtpd_client_restrictions=permit_mynetworks,reject
-o smtpd_recipient_restrictions=permit_mynetworks,reject
-o smtpd_delay_reject=no
-o smtpd_helo_restrictions=
-o smtpd_sender_restrictions=
-o smtpd_data_restrictions=reject_unauth_pipelining
-o smtpd_end_of_data_restrictions=
-o smtpd_restriction_classes=
-o smtpd_error_sleep_time=0
-o smtpd_soft_error_limit=1001
-o smtpd_hard_error_limit=1000
-o smtpd_client_connection_count_limit=0
-o smtpd_client_connection_rate_limit=0
-o receive_override_options=no_header_body_checks,no_unknown_recipient_checks,no_milters,no_address_mappings
-o local_header_rewrite_clients=
-o smtpd_milters=
-o local_recipient_maps=
-o relay_recipient_maps=
pickup unix n - y 60 1 pickup
cleanup unix n - y - 0 cleanup
-o header_checks=regexp:/etc/postfix/header_checks
qmgr unix n - n 300 1 qmgr
tlsmgr unix - - y 1000? 1 tlsmgr
rewrite unix - - y - - trivial-rewrite
bounce unix - - y - 0 bounce
defer unix - - y - 0 bounce
trace unix - - y - 0 bounce
verify unix - - y - 1 verify
flush unix n - y 1000? 0 flush
proxymap unix - - n - - proxymap
proxywrite unix - - n - 1 proxymap
smtp unix - - y - - smtp
relay unix - - y - - smtp
-o syslog_name=postfix/$service_name
showq unix n - y - - showq
error unix - - y - - error
retry unix - - y - - error
discard unix - - y - - discard
local unix - n n - - local
virtual unix - n n - - virtual
lmtp unix - - y - - lmtp
anvil unix - - y - 1 anvil
scache unix - - y - 1 scache
postlog unix-dgram n - n - 1 postlogd
maildrop unix - n n - - pipe
flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}
uucp unix - n n - - pipe
flags=Fqhu user=uucp argv=uux -r -n -z -a$sender - $nexthop!rmail ($recipient)
ifmail unix - n n - - pipe
flags=F user=ftn argv=/usr/lib/ifmail/ifmail -r $nexthop ($recipient)
bsmtp unix - n n - - pipe
flags=Fq. user=bsmtp argv=/usr/lib/bsmtp/bsmtp -t$nexthop -f$sender $recipient
scalemail-backend unix - n n - 2 pipe
flags=R user=scalemail argv=/usr/lib/scalemail/bin/scalemail-store ${nexthop} ${user} ${extension}
mailman unix - n n - - pipe
flags=FR user=list argv=/usr/lib/mailman/bin/postfix-to-mailman.py
${nexthop} ${user}
我已經嘗試了各種 mydestination 設定。
感謝您的幫助 !
答案1
Postfix 可能會選擇virtual
它實際上不應該處理的網域您的其中一個查找不應該返回(任何)結果:假陽性。
它很可能transport_maps
或virtual_mailbox_domains
(預設為推遲到virtual_mailbox_maps
)。如果你已經證明了這個理論兩個都您的網域和實際上應該中繼的網域會根據您配置的尋找之一產生結果,例如嘗試以下操作:
postmap -q [email protected] sqlite:/etc/postfix/sqlite_virtual_mailbox_maps.cf
postmap -q [email protected] sqlite:/etc/postfix/sqlite_virtual_mailbox_maps.cf
postmap -q @other.example sqlite:/etc/postfix/sqlite_virtual_mailbox_maps.cf
postmap -q mydomain.example sqlite:/etc/postfix/sqlite_transports_maps.cf
postmap -q other.example sqlite:/etc/postfix/sqlite_transports_maps.cf
如果兩者都得到結果,請仔細查看查詢,特別是WHERE
帶有佔位符的子句(以 開頭%
)和確定為什麼它會為您未明確放入資料庫的網域傳回更多結果。傳回金鑰本身或靜態結果是在 Postfix 中很常見,因此它不會觸發警告..它對您的情況沒有用處。
我沒用過阿瑪維斯這樣,但我相信壓倒一切運輸像這樣的標準用例不需要 Postfix 中的。相反,使用 Postfix 將檢查相應的事實運輸_mailbox_domains 尋找以決定如何傳輸哪些網域和郵箱。
virtual_mailbox_domains
您可能不需要為此覆蓋傳輸,並且如果您列出虛擬域而不是transport_maps
僅將後者用於特定覆蓋,則可能會獲得更靈活且不易出錯的設定。