Email

Dovecot + Postfix 可以發送但電子郵件不會顯示在收件箱中

  • August 6, 2020

我正在嘗試在我的個人網站伺服器上設置電子郵件伺服器。我大部分時間都在那裡,我可以發送電子郵件,但向我設置的地址發送電子郵件似乎沒有用新文件填充curornew目錄中的Inboxor目錄。Junk雖然Sent在發送電子郵件後會填充(這似乎總是成功)。

相關軟體包的守護程序處於活動狀態,似乎沒有任何警告/錯誤。MX 記錄等似乎沒問題,DKIM 測試說一切都很好,而且我不在任何垃圾郵件列表中。在這一點上,我基本上迷路了。

我在具有以下軟體包版本的個人伺服器上使用 Arch Linux:

postfix 3.5.6-1
dovecot 2.3.10.1-2
opendkim 2.10.3-7
pigeonhole 0.5.10-2
procmail 3.22-10
spamassassin 3.4.4-3

這是系統日誌的一部分(我認為不允許 postfix 擁有自己的日誌?)。這是唯一似乎有有價值資訊的部分,雖然我不明白。某種 milter 問題?(我也替換了個人辨識資訊,例如 IP 和域名)

Aug 05 13:01:29 user postfix/cleanup[94749]: 836A924F0B: message-id=<20200805200130.tu32pspohyf3ym53@dirac.localdomain>
Aug 05 13:01:29 user postfix/qmgr[94666]: 836A924F0B: from=<user@domain.com>, size=499, nrcpt=1 (queue active)
Aug 05 13:01:29 user postfix/submission/smtpd[94741]: public/cleanup socket: wanted attribute: status
Aug 05 13:01:29 user postfix/submission/smtpd[94741]: input attribute name: status
Aug 05 13:01:29 user postfix/submission/smtpd[94741]: input attribute value: 0
Aug 05 13:01:29 user postfix/submission/smtpd[94741]: public/cleanup socket: wanted attribute: reason
Aug 05 13:01:29 user postfix/submission/smtpd[94741]: input attribute name: reason
Aug 05 13:01:29 user postfix/submission/smtpd[94741]: input attribute value: (end)
Aug 05 13:01:29 user postfix/submission/smtpd[94741]: public/cleanup socket: wanted attribute: (list terminator)
Aug 05 13:01:29 user postfix/submission/smtpd[94741]: input attribute name: (end)
Aug 05 13:01:29 user postfix/submission/smtpd[94741]: > unknown[666.666.666.666]: 250 2.0.0 Ok: queued as 836A924F0B
Aug 05 13:01:29 user postfix/submission/smtpd[94741]: abort all milters
Aug 05 13:01:29 user postfix/submission/smtpd[94741]: milter8_abort: abort milter inet:127.0.0.1:12301
Aug 05 13:01:29 user postfix/submission/smtpd[94741]: < unknown[666.666.666.666]: QUIT
Aug 05 13:01:29 user postfix/submission/smtpd[94741]: > unknown[666.666.666.666]: 221 2.0.0 Bye
Aug 05 13:01:29 user postfix/submission/smtpd[94741]: match_hostname: smtpd_client_event_limit_exceptions: unknown ~? 127.0.0.1/32Aug 05 13:01:29 user postfix/submission/smtpd[94741]: match_hostaddr: smtpd_client_event_limit_exceptions: 666.666.666.666 ~? 127.0.0.1/32
Aug 05 13:01:29 user postfix/submission/smtpd[94741]: match_hostname: smtpd_client_event_limit_exceptions: unknown ~? 777.777.777.777/32
Aug 05 13:01:29 user postfix/submission/smtpd[94741]: match_hostaddr: smtpd_client_event_limit_exceptions: 666.666.666.666 ~? 777.777.777.777/32
Aug 05 13:01:29 user postfix/submission/smtpd[94741]: match_list_match: unknown: no match
Aug 05 13:01:29 user postfix/submission/smtpd[94741]: match_list_match: 666.666.666.666: no match
Aug 05 13:01:29 user postfix/submission/smtpd[94741]: send attr request = disconnect
Aug 05 13:01:29 user postfix/submission/smtpd[94741]: send attr ident = submission666.666.666.666:
Aug 05 13:01:29 user postfix/submission/smtpd[94741]: private/anvil: wanted attribute: status
Aug 05 13:01:29 user postfix/submission/smtpd[94741]: input attribute name: status
Aug 05 13:01:29 user postfix/submission/smtpd[94741]: input attribute value: 0
Aug 05 13:01:29 user postfix/submission/smtpd[94741]: private/anvil: wanted attribute: (list terminator)
Aug 05 13:01:29 user postfix/submission/smtpd[94741]: input attribute name: (end)
Aug 05 13:01:29 user postfix/submission/smtpd[94741]: abort all milters
Aug 05 13:01:29 user postfix/submission/smtpd[94741]: milter8_abort: abort milter inet:127.0.0.1:12301
Aug 05 13:01:29 user postfix/submission/smtpd[94741]: disconnect event to all milters
Aug 05 13:01:29 user postfix/submission/smtpd[94741]: milter8_disc_event: quit milter inet:127.0.0.1:12301
Aug 05 13:01:29 user postfix/submission/smtpd[94741]: disconnect from unknown[666.666.666.666] ehlo=2 starttls=1 auth=1 mail=1 rcpt=1 data=1 quit=1 commands=8
Aug 05 13:01:29 user postfix/submission/smtpd[94741]: free all milters
Aug 05 13:01:29 user postfix/submission/smtpd[94741]: free milter inet:127.0.0.1:12301
Aug 05 13:01:29 user postfix/submission/smtpd[94741]: master_notify: status 1
Aug 05 13:01:29 user postfix/submission/smtpd[94741]: connection closed
Aug 05 13:01:29 user postfix/smtp[94750]: 836A924F0B: to=<user@domain.com>, relay=none, delay=0.38, delays=0.21/0.06/0.11/0, dsn=5.4.6, status=bounced (mail for domain.com loops back to myself)
Aug 05 13:01:30 user postfix/cleanup[94749]: 00DA924F0E: message-id=<20200805200130.00DA924F0E@mail.domain.com>
Aug 05 13:01:30 user postfix/bounce[94751]: 836A924F0B: sender non-delivery notification: 00DA924F0E
Aug 05 13:01:30 user postfix/qmgr[94666]: 00DA924F0E: from=<>, size=2965, nrcpt=1 (queue active)
Aug 05 13:01:30 user postfix/qmgr[94666]: 836A924F0B: removed
Aug 05 13:01:30 user postfix/smtp[94750]: 00DA924F0E: to=<user@domain.com>, relay=none, delay=0.06, delays=0.02/0/0.04/0, dsn=5.4.6, status=bounced (mail for domain.com loops back to myself)
Aug 05 13:01:30 user postfix/qmgr[94666]: 00DA924F0E: removed

我已經打開了必要的埠並進行了驗證。線上埠檢查工具確認。在這裡 (v6)

埠偵聽似乎按預期工作。這裡有一段lsof -iTCP -sTCP:LISTEN -P

COMMAND     PID     USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
dovecot   92963     root   21u  IPv4 963311      0t0  TCP *:110 (LISTEN)
dovecot   92963     root   22u  IPv6 963312      0t0  TCP *:110 (LISTEN)
dovecot   92963     root   23u  IPv4 963313      0t0  TCP *:995 (LISTEN)
dovecot   92963     root   24u  IPv6 963314      0t0  TCP *:995 (LISTEN)
dovecot   92963     root   39u  IPv4 963359      0t0  TCP *:143 (LISTEN)
dovecot   92963     root   40u  IPv6 963360      0t0  TCP *:143 (LISTEN)
dovecot   92963     root   41u  IPv4 963361      0t0  TCP *:993 (LISTEN)
dovecot   92963     root   42u  IPv6 963362      0t0  TCP *:993 (LISTEN)
master    93066     root   88u  IPv4 964097      0t0  TCP *:25 (LISTEN)
master    93066     root   91u  IPv4 964100      0t0  TCP *:587 (LISTEN)
master    93066     root   94u  IPv4 964103      0t0  TCP *:465 (LISTEN)
opendkim  93089 opendkim    3u  IPv4 964461      0t0  TCP localhost:12301 (LISTEN)
spamd     93121     root    6u  IPv6 964939      0t0  TCP localhost:783 (LISTEN)
spamd     93121     root    7u  IPv4 964941      0t0  TCP localhost:783 (LISTEN)
spamd\x20 93144    spamd    6u  IPv6 964939      0t0  TCP localhost:783 (LISTEN)
spamd\x20 93144    spamd    7u  IPv4 964941      0t0  TCP localhost:783 (LISTEN)
spamd\x20 93145    spamd    6u  IPv6 964939      0t0  TCP localhost:783 (LISTEN)
spamd\x20 93145    spamd    7u  IPv4 964941      0t0  TCP localhost:783 (LISTEN)
smtp      93244  postfix    6u  IPv4 964097      0t0  TCP *:25 (LISTEN)

以下是後綴 main.cf 的內容

compatibility_level = 2
queue_directory = /var/spool/postfix
command_directory = /usr/bin
daemon_directory = /usr/lib/postfix/bin
data_directory = /var/lib/postfix
mail_owner = postfix
unknown_local_recipient_reject_code = 550
alias_maps = hash:/etc/postfix/aliases
alias_database = $alias_maps
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
sendmail_path = /usr/bin/sendmail
newaliases_path = /usr/bin/newaliases
mailq_path = /usr/bin/mailq
setgid_group = postdrop
html_directory = no
manpage_directory = /usr/share/man
sample_directory = /etc/postfix
readme_directory = /usr/share/doc/postfix
inet_protocols = ipv4
meta_directory = /etc/postfix
shlib_directory = /usr/lib/postfix
smtpd_tls_key_file = /etc/letsencrypt/live/mail.domain.com/privkey.pem
smtpd_tls_cert_file = /etc/letsencrypt/live/mail.domain.com/fullchain.pem
smtpd_use_tls = yes
smtpd_tls_auth_only = yes
smtp_tls_security_level = may
smtp_tls_loglevel = 1
smtpd_sasl_auth_enable = yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
home_mailbox = ~/Mail/Inbox/
#smtpd_milters = inet:localhost:12301 #Can't find localhost? is there some issue with /etc/hosts?
#non_smtpd_milters = inet:localhost:12301
#127.0.0.1 should work anyway I think
smtpd_milters = inet:127.0.0.1:12301
non_smtpd_milters = inet:127.0.0.1:12301
smtpd_sasl_security_options = noanonymous, noplaintext
smtpd_sasl_tls_security_options = noanonymous
myhostname = mail.domain.com
milter_default_action = accept
milter_protocol = 6

以下是master.cf的內容

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
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
postlog   unix-dgram n  -       n       -       1       postlogd
smtp unix - - n - - smtp 
smtp inet n - y - - smtp -v
 -o content_filter=spamassassin 
submission inet n       -       y       -       -       smtpd -v
 -o syslog_name=postfix/submission
 -o smtpd_tls_security_level=encrypt
 -o smtpd_sasl_auth_enable=yes
 -o smtpd_tls_auth_only=yes
submissions     inet  n       -       y       -       -       smtpd -v
 -o syslog_name=postfix/smtps
 -o smtpd_tls_wrappermode=yes
 -o smtpd_sasl_auth_enable=yes
spamassassin unix -     n       n       -       -       pipe
 user=spamd argv=/usr/bin/vendor_perl/spamc -f -e /usr/sbin/sendmail -oi -f ${sender} ${recipient}" 

以下是 dovecot.conf 的內容

ssl = required
ssl_cert = </etc/letsencrypt/live/mail.domain.com/fullchain.pem
ssl_key = </etc/letsencrypt/live/mail.domain.com/privkey.pem
ssl_dh = </etc/dovecot/dh.pem

auth_mechanisms = plain login
protocols = $protocols imap
disable_plaintext_auth = no
mail_privileged_group = mail

userdb {
       driver = passwd
}
passdb {
       driver = pam
       args = session=yes failure_show_msg=yes
}


mail_location = maildir:~/Mail:INBOX=~/Mail/Inbox:LAYOUT=fs
namespace inbox {
       inbox = yes
      
       mailbox Drafts {
       special_use = \Drafts
       auto = create
       }

       mailbox Junk {
       special_use = \Junk
       auto = create
       autoexpunge = 30d
       }
       
       mailbox Sent {
       special_use = \Sent
       auto = create
       }

       mailbox Trash {
       special_use = \Trash
       auto = create
       }

       mailbox Archive {
       special_use = \Archive
       auto = create
       }
       mailbox Done {
       auto = create
       }
}

service auth {
 unix_listener /var/spool/postfix/private/auth {
       mode = 0660
       user = postfix
       group = postfix
   }
}

protocol lda {
 mail_plugins = $mail_plugins sieve
}

protocol lmtp {
 mail_plugins = $mail_plugins sieve
}

plugin {
       sieve = ~/.dovecot.sieve
       sieve_default = /var/lib/dovecot/sieve/default.sieve
       sieve_dir = ~/.sieve
       sieve_global_dir = /var/lib/dovecot/sieve/
}

#Logging
log_path = /var/log/dovecot.log
auth_verbose = yes
mail_debug = yes
auth_debug = yes
auth_debug_passwords = yes
verbose_ssl=yes

/etc/postfix/aliases 的內容

mailer-daemon: postmaster
postmaster: root
root: user 
nobody: root
hostmaster: root
usenet: root
news: root
webmaster: root
www: root
ftp: root
abuse: root
noc: root
security: root

/var/lib/dovecot/sieve/default.sieve 的內容

require ["fileinto", "mailbox"];
if header :contains "X-Spam-Flag" "YES"
       {
               fileinto "Junk";
       }   

/etc/opendkim/opendkim.conf 的內容

BaseDirectory           /var/lib/opendkim
Domain                  tzcrawford.com
KeyFile                 /etc/opendkim/mail.private
Selector                mail
Socket                  inet:12301@localhost
Syslog                  Yes
TemporaryDirectory      /run/opendkim
UMask                   002
Canonicalization        relaxed/simple
KeyTable file:/etc/opendkim/keytable
SigningTable refile:/etc/opendkim/signingtable
InternalHosts refile:/etc/opendkim/trustedhost

如果您有任何想法或想了解更多資訊,請告訴我,謝謝!

Postfix 尚未配置為接受您的域名的郵件,因此當它查找域的 MX 記錄並發現它將自己指定為要發送到的郵件伺服器時,它會拋出錯誤“郵件循環回我自己”。因為它實際上並不接受您域的郵件,所以它唯一能做的就是退回郵件。

然後我們看到退回郵件本身也出於同樣的原因被退回。然後發生的事情是在您沒有發布的後續日誌條目中,但通常這樣的消息會被丟棄或記錄在某處。

您需要配置 Postfix 以接受您的域名的郵件。這需要設置 obth 中的myorigin=指令main.cf,該指令應設置為$mydomain和該mydestination=指令,該指令應包括本地目的地郵件的多個值:

myorigin = $mydomain
mydestination = $myhostname, localhost.$mydomain $mydomain

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