Postfix

Postfix & Dovecot:郵件顯示在已發送但收件箱中沒有

  • May 25, 2020

簡而言之,我的問題:

我在 ubuntu 伺服器 18.04 上有一個本地郵件伺服器(postfix 和 dovecot 並使用自分配 SSL,openssl),我可以從同一網路中的另一台電腦登錄(僅收到有關自分配 ssl 的警告)。

但是當我嘗試發送電子郵件(給同一使用者或其他使用者)時,我會在已發送文件夾中看到郵件。但收件箱中沒有。這是我的 /var/log/mail.log 輸出:

May 25 13:44:17 tsun postfix/submission/smtpd[19418]: Anonymous TLS connection established from unknown[192.168.7.17]: TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
May 25 13:44:17 tsun postfix/submission/smtpd[19418]: BBA4C802F5: client=unknown[192.168.7.17], sasl_method=PLAIN, sasl_username=veelst
May 25 13:44:17 tsun postfix/cleanup[19425]: BBA4C802F5: message-id=<1c36cd2d-de87-5c32-d053-847623cde2bd@tsun.net>
May 25 13:44:17 tsun postfix/qmgr[19411]: BBA4C802F5: from=<veelst@tsun.net>, size=584, nrcpt=1 (queue active)
May 25 13:44:17 tsun postfix/smtp[19426]: BBA4C802F5: to=<veelst@tsun.net>, relay=none, delay=0.06, delays=0.05/0.01/0/0, dsn=5.4.6, status=bounced (mail for tsun.net loops back to myself)
May 25 13:44:17 tsun postfix/cleanup[19425]: D3AE1802F7: message-id=<20200525134417.D3AE1802F7@mail.tsun.net>
May 25 13:44:17 tsun postfix/submission/smtpd[19418]: disconnect from unknown[192.168.7.17] ehlo=2 starttls=1 auth=1 mail=1 rcpt=1 data=1 quit=1 commands=8
May 25 13:44:17 tsun postfix/bounce[19427]: BBA4C802F5: sender non-delivery notification: D3AE1802F7
May 25 13:44:17 tsun postfix/qmgr[19411]: D3AE1802F7: from=<>, size=2425, nrcpt=1 (queue active)
May 25 13:44:17 tsun postfix/qmgr[19411]: BBA4C802F5: removed
May 25 13:44:17 tsun postfix/smtp[19426]: D3AE1802F7: to=<veelst@tsun.net>, relay=none, delay=0.04, delays=0.04/0/0/0, dsn=5.4.6, status=bounced (mail for tsun.net loops back to myself)
May 25 13:44:17 tsun postfix/qmgr[19411]: D3AE1802F7: removed
May 25 13:44:18 tsun dovecot: imap(veelst)<19277><Nqj5HnmmNMzAqAcR>: Connection closed (IDLE running for 0.001 + waiting input for 0.002 secs, 0.001 in locks, 2 B in + 10 B out, state=wait-input) in=906 out=301$
May 25 13:44:18 tsun dovecot: imap-login: Login: user=<veelst>, method=PLAIN, rip=192.168.7.17, lip=192.168.7.146, mpid=19429, TLS, session=</PPpLHmmhM3AqAcR>

詳細說明:

我有一個執行 Ubuntu Server 18.04 的本地郵件伺服器,IP 地址為 192.168.7.146

主機名的輸出:

veelst@tsun:/var/mail$ hostnamectl 
  Static hostname: tsun
        ...
 Operating System: Ubuntu 18.04.1 LTS
           Kernel: Linux 4.15.0-101-generic
     Architecture: x86-64

有後綴和鴿舍:

postconf mail_version
mail_version = 3.3.0
dovecot --version
2.3.10.1 (a3d0e1171)

在另一台機器上,我安裝了 BIND9 DNS 伺服器,並帶有以下指向郵件伺服器的區域:

$ttl 38400
tsun.net.   IN  SOA thome.local. admin.tsun.net. (
           1589393672
           10800
           3600
           604800
           38400 )
tsun.net.   IN  NS  thome.local.
mail.tsun.net. 3600 IN A   192.168.7.146
tsun.net.      3600 IN MX  0 mail.tsun.net.
tsun.net.      3600 IN TXT "v=spf1 mx ~all"
tsun.net.   IN  A   192.168.7.146

正如我上面所說,我可以使用雷鳥在同一網路上使用我的電腦登錄。埠也可以從我的電腦上訪問,sudo nmap mail.tsun.net 命令的輸出:

Starting Nmap 7.80 ( https://nmap.org ) at 2020-05-25 13:34 +03
Nmap scan report for mail.tsun.net (192.168.7.146)
Host is up (0.00074s latency).
rDNS record for 192.168.7.146: msun
Not shown: 991 closed ports
PORT    STATE SERVICE
22/tcp  open  ssh
25/tcp  open  smtp
80/tcp  open  http
110/tcp open  pop3
143/tcp open  imap
465/tcp open  smtps
587/tcp open  submission
993/tcp open  imaps
995/tcp open  pop3s

Nmap done: 1 IP address (1 host up) scanned in 4.04 seconds

關於我的設置的其他一些有用資訊:

鴿舍-n:

# 2.3.10.1 (a3d0e1171): /etc/dovecot/dovecot.conf
# OS: Linux 4.15.0-101-generic x86_64 Ubuntu 18.04.1 LTS 
# Hostname: tsun
auth_mechanisms = plain login
mail_location = mbox:~/mail:INBOX=/var/mail/%u
mail_privileged_group = mail
namespace inbox {
 inbox = yes
 location = 
 mailbox Drafts {
   auto = create
   special_use = \Drafts
 }
 mailbox Junk {
   auto = create
   special_use = \Junk
 }
 mailbox Sent {
   special_use = \Sent
 }
 mailbox "Sent Messages" {
   special_use = \Sent
 }
 mailbox Trash {
   auto = create
   special_use = \Trash
 }
 prefix = 
}
passdb {
 driver = pam
}
protocols = imap pop3
service auth {
 unix_listener /var/spool/postfix/private/auth {
   group = postfix
   mode = 0660
   user = postfix
 }
}
service lmtp {
 unix_listener /var/spool/postfix/private/dovecot-lmtp {
   group = postfix
   mode = 0600
   user = postfix
 }
}
ssl_cert = </var/www/cert/certificate.pem
ssl_key = # hidden, use -P to show it
ssl_min_protocol = TLSv1.2
ssl_prefer_server_ciphers = yes
userdb {
 driver = passwd
}

後置信-n:

alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
append_dot_mydomain = no
biff = no
compatibility_level = 2
inet_interfaces = all
inet_protocols = all
mailbox_size_limit = 0
mailbox_transport = lmtp:unix:private/dovecot-lmtp
message_size_limit = 52428800
mydestination = $myhostname, localhost.tsun.net, localhost
myhostname = mail.tsun.net
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_loglevel = 1
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 (Ubuntu)
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
smtpd_tls_cert_file = /var/www/cert/certificate.pem
smtpd_tls_key_file = /var/www/cert/key.pem
smtpd_tls_loglevel = 1
smtpd_tls_mandatory_protocols = !SSLv2, !SSLv3, !TLSv1, !TLSv1.1
smtpd_tls_protocols = !SSLv2, !SSLv3, !TLSv1, !TLSv1.1
smtpd_tls_security_level = may
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtpd_use_tls = yes
smtputf8_enable = no

我也用這個命令來創建我的 ssl

$openssl genrsa -out key.pem 2048
$openssl req -new -sha256 -key key.pem -out csr.csr
$sudo openssl req -x509 -sha256 -days 365 -key key.pem -in csr.csr -out certificate.pem
$openssl req -in csr.csr -text -noout | grep -i "Signature.*SHA256" && echo "All is well" || echo "This certificate will stop working in 2017! You must update OpenSSL to generate a widely-compatible certificate"

(我得到“一切都好”的輸出)

解決了我的問題後。我在日誌中收到新錯誤:

[private/dovecot-lmtp]: Connection refused

通過將 lmtp 添加到 /etc/dovecot/dovecot.conf 中的協議來修復它:

protocols = imap pop3 lmtp

這修復了連接被拒絕的錯誤。

然後我得到了找不到使用者的新錯誤。必須通過轉到 /etc/dovecot/conf.d/10-auth.conf 並取消註釋該行來修復它:

auth_username_format = %n

現在我可以從同一個網路發送和接收郵件就好了!

Postfix 告訴你確切的原因:

status=bounced (mail for tsun.net loops back to myself)

嘗試添加tsun.netmydestination您的/etc/postfix/main.cf. 你告訴它的那一行應該是域“localhost.tsun.net”和“localhost”。也許是錯字?

然後重新啟動您的 Postfix 守護程序:

/etc/init.d/postfix restart

引用自:https://serverfault.com/questions/1018623