Ubuntu

使用 dovecot + postfix 設置無法接收郵件

  • August 26, 2019

第一次在執行最新 Ubuntu 的機器上設置我自己的郵件伺服器

環顧四周後,我決定使用 dovecot + postfix 和在 /var/mail/vmail/%d/%n 中有郵箱的虛擬使用者

在大多數情況下,我遵循此處找到的收回電子郵件教程系列

我注意到當我嘗試通過 IMAP 連接到 me@mydomain.com 時,會創建正確的目錄結構,因此 /var/mail/vmail/mydomain.com/me 存在並且其中包含所需的文件。

但是,當我通過 SMTP 在該伺服器上接收郵件時,從 Postfix 到 Dovecot 的整個命令鏈中似乎有一個點,其中域部分 %d 變為空,因此它嘗試訪問和創建錯誤的目錄並失敗這個錯誤:

Jan 25 17:47:35 lda(me): Debug: Effective uid=1000, gid=1000, home=/home/me
Jan 25 17:47:35 lda(me): Debug: Namespace inbox: type=private, prefix=, sep=, inbox=yes, hidden=no, list=yes, subscriptions=yes location=maildir:/var/mail/vmail//me/mail:LAYOUT=fs
Jan 25 17:47:35 lda(me): Debug: fs: root=/var/mail/vmail//me/mail, index=, indexpvt=, control=, inbox=/var/mail/vmail//me/mail, alt=
Jan 25 17:47:35 lda(me): Debug: Namespace : /var/mail/vmail//me/mail doesn't exist yet, using default permissions
Jan 25 17:47:35 lda(me): Debug: Namespace : Using permissions from /var/mail/vmail//me/mail: mode=0700 gid=default
Jan 25 17:47:35 lda(me): Error: User initialization failed: Namespace '': mkdir(/var/mail/vmail//me/mail) failed: Permission denied (euid=1000(me) egid=1000(me) missing +w perm: /var/mail/vmail/, we're not in group 5000(vmail), dir owned by 5000:5000 mode=0775)
Jan 25 17:47:35 lda(me): Fatal: Invalid user settings. Refer to server log for more information.

/var/mail/vmail 歸 vmail:vmail (5000) 所有,即使沒有必要,我還是暫時將使用者 me 添加到了 vmail 組。

我不確定如何進行調試,我已經為從 postfix 到 dovecot 的所有內容打開了詳細模式,但是從我得到的日誌中我無法查明問題的確切根源。

這是我的後綴 master.cf 的相關部分

dovecot   unix  -       n       n       -       -       pipe
 flags=DRhu user=vmail:vmail argv=/usr/lib/dovecot/deliver
 -f ${sender} -d ${recipient}

非常感謝任何形式的幫助或建議

更新 1

原來有一個mailbox_command在postfix中沒有正確設置所以我把它從

#mailbox_command = /usr/lib/dovecot/deliver -c /etc/dovecot/dovecot.conf -m "${EXTENSION}"

mailbox_command = /usr/lib/dovecot/deliver -c /etc/dovecot/dovecot.conf -f "${SENDER}" -d "${RECIPIENT}"

現在我沒有收到權限被拒絕錯誤,但我仍然無法接收電子郵件

郵件位置設置為:

mail_home = /var/mail/vmail/%d/%n
mail_location = maildir:/var/mail/vmail/%d/%n/mail:LAYOUT=fs

virtual-mailbox-users 的內容是:

me@mydomain.com       mydomain.com/me

是的,我在每次修改後都對該文件進行了 postmap

我注意到其他一些警告/錯誤:

Jan 25 20:43:29 linux2-dkhalife postfix/smtpd[8277]: warning: SASL: Connect to private/dovecot-auth failed: Connection refused
Jan 25 20:43:29 linux2-dkhalife postfix/smtpd[8277]: fatal: no SASL authentication mechanisms
Jan 25 20:42:26 linux2-dkhalife postfix/smtpd[8274]: warning: connect to Milter service unix:/var/spool/postfix/spamassassin/spamd.sock: No such file or directory
Jan 25 20:42:26 linux2-dkhalife postfix/smtpd[8274]: warning: connect to Milter service unix:/var/run/clamav/clamav-milter.ctl: No such file or directory
Jan 25 20:42:26 linux2-dkhalife postfix/smtpd[8274]: warning: connect to Milter service unix:/var/run/opendkim/opendkim.sock: No such file or directory

更新 2

doveconf -n 輸出版本 2.2.18 和以下內容:

auth_mechanisms = plain login
mail_debug = yes
mail_home = /var/mail/vmail/%d/%n
mail_location = maildir:/var/mail/vmail/%d/%n/mail:LAYOUT=fs
mail_privileged_group = vmail
managesieve_notify_capability = mailto
managesieve_sieve_capability = fileinto reject envelope encoded-character vacation subaddress comparator-i;ascii-numeric relational regex imap4flags copy include variables body enotify environment mailbox date index ihave duplicate
namespace inbox {
 inbox = yes
 location =
 mailbox Drafts {
   auto = subscribe
   special_use = \Drafts
 }
 mailbox Junk {
   auto = subscribe
   special_use = \Junk
 }
 mailbox Sent {
   auto = subscribe
   special_use = \Sent
 }
 mailbox "Sent Messages" {
   auto = subscribe
   special_use = \Sent
 }
 mailbox Trash {
   auto = subscribe
   special_use = \Trash
 }
 prefix =
}
passdb {
 args = username_format=%u scheme=ssha512 /etc/dovecot/passwd.db
 driver = passwd-file
}
plugin {
 sieve = ~/.dovecot.sieve
 sieve_after = /var/mail/vmail/sieve-after
 sieve_before = /var/mail/vmail/sieve-before
 sieve_dir = ~/sieve
}
protocols = imap pop3 sieve
service auth {
 unix_listener /var/spool/postfix/private/auth {
   group = postfix
   mode = 0660
   user = postfix
 }
}
ssl_cert = </etc/ssl/private/mail_mydomain_com.pem
ssl_cipher_list = ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AES:RSA+3DES:!ADH:!AECDH:!MD5:!DSS
ssl_client_ca_dir = /etc/ssl/certs
ssl_key = </etc/ssl/private/mail_mydomain_com.key
userdb {
 args = uid=5000 gid=5000 home=/var/mail/vmail/%d/%n
 driver = static
}
protocol imap {
 imap_client_workarounds = delay-newmail tb-extra-mailbox-sep
 mail_max_userip_connections = 10
}
protocol pop3 {
 mail_max_userip_connections = 10
 pop3_client_workarounds = outlook-no-nuls oe-ns-eoh
}
protocol lda {
 deliver_log_format = msgid=%m: %$
 mail_plugins = sieve
 postmaster_address = postmaster@mydomain.com
 quota_full_tempfail = yes
 rejection_reason = Your message to <%t> was automatically rejected:%n%r
}

postconf -n 輸出版本 2.11.3 和以下內容:

alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
append_dot_mydomain = no
biff = no
broken_sasl_auth_clients = yes
canonical_maps = hash:/etc/postfix/canonical
config_directory = /etc/postfix
default_destination_concurrency_limit = 5
disable_vrfy_command = yes
dovecot_destination_recipient_limit = 1
home_mailbox = Maildir/
inet_interfaces = all
inet_protocols = all
local_recipient_maps =
mailbox_command = /usr/lib/dovecot/deliver -c /etc/dovecot/dovecot.conf -f "${SENDER}" -d "${RECIPIENT}"
mailbox_size_limit = 0
message_size_limit = 104857600
milter_connect_macros = j {daemon_name} v {if_name} _
milter_default_action = accept
mydestination = mydomain.com, myotherdomain.ca, localhost
mydomain = mydomain.com
myhostname = mail.mydomain.com
mynetworks = 127.0.0.0/8 10.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
myorigin = /etc/mailname
non_smtpd_milters = $smtpd_milters
readme_directory = no
recipient_delimiter = +
relay_destination_concurrency_limit = 1
relayhost =
smtp_tls_note_starttls_offer = yes
smtp_tls_security_level = may
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtp_use_tls = yes
smtpd_banner = $myhostname ESMTP
smtpd_helo_required = yes
smtpd_helo_restrictions = permit_mynetworks reject_non_fqdn_helo_hostname, reject_invalid_helo_hostname, reject_unknown_helo_hostname, permit
smtpd_milters = unix:/var/spool/postfix/spamassassin/spamd.sock unix:/var/run/clamav/clamav-milter.ctl unix:/var/run/opendkim/opendkim.sock
smtpd_recipient_restrictions = reject_unknown_client_hostname, reject_unknown_sender_domain, reject_unknown_recipient_domain, reject_unauth_pipelining, permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination, reject_invalid_hostname, reject_non_fqdn_sender
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
smtpd_sasl_auth_enable = yes
smtpd_sasl_authenticated_header = yes
smtpd_sasl_local_domain = $myhostname
smtpd_sasl_path = /var/spool/postfix/private/dovecot-auth
smtpd_sasl_security_options = noanonymous
smtpd_sasl_type = dovecot
smtpd_sender_login_maps = $virtual_mailbox_maps
smtpd_sender_restrictions = reject_unknown_sender_domain, reject_sender_login_mismatch
smtpd_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
smtpd_tls_ask_ccert = yes
smtpd_tls_auth_only = yes
smtpd_tls_cert_file = /etc/ssl/private/mail_mydomain_com.pem
smtpd_tls_ciphers = high
smtpd_tls_key_file = /etc/ssl/private/mail_mydomain_com.key
smtpd_tls_loglevel = 0
smtpd_tls_mandatory_ciphers = medium
smtpd_tls_mandatory_protocols = SSLv3, TLSv1
smtpd_tls_received_header = yes
smtpd_tls_security_level = may
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtpd_tls_session_cache_timeout = 3600s
smtpd_use_tls = yes
tls_random_source = dev:/dev/urandom
unknown_address_reject_code = 550
unknown_client_reject_code = 550
unknown_hostname_reject_code = 550
virtual_alias_maps = hash:/etc/postfix/virtual
virtual_mailbox_base = /var/mail/vmail
virtual_mailbox_domains = hash:/etc/postfix/virtual-mailbox-domains
virtual_mailbox_maps = hash:/etc/postfix/virtual-mailbox-users
virtual_transport = dovecot

首先,您smtpd_sasl_path既錯誤又錯誤地指定了。在 dovecot.conf 中,您/var/spool/postfix/private/auth在 Postfix 中將其設置為應該是smtpd_sasl_path = private/auth(而不是.../dovecot-auth)。注意這是一個相對路徑,相對於 Postfix 的 chroot 目錄。重新啟動 Postfix,SASL 錯誤應該消失了。

其次,看起來您正在混合虛擬郵件託管和“規範”郵件託管。您的虛擬域不能設置在 中mydestination,否則您會遇到諸如“郵件循環回自己”之類的問題。決定你想要什麼樣的郵件託管設置,並相應地配置 Postfix 和 Dovecot。不要試圖混合和匹配配置指令,希望某種組合會隨機產生可行的結果。

這兩個問題可能是您問題的根源。Dovecot 的錯誤資訊暗示了這一點:

Jan 25 17:47:35 lda(dany): Error: User initialization failed: Namespace '':
 mkdir(/var/mail/vmail//dany/mail) failed:
 Permission denied (euid=1000(dany) egid=1000(dany) missing +w perm:
 /var/mail/vmail/, we're not in group 5000(vmail), dir owned by 5000:5000 mode=0775)

這是因為 Postfix 嘗試使用mailbox_command(Dovecot 的 LDA deliver)作為接收消息的使用者(dany)傳遞郵件,但該使用者當然沒有業務寫入,/var/mail/vmail因為它是虛擬使用者。

我將假設您想要適當的虛擬郵件託管,例如在http://www.postfix.org/VIRTUAL_README.html中討論的。

  • 您的 Dovecotmail_location設置應該只是mail_location = maildir:~/mail:LAYOUT=fs(並問自己是否真的想要LAYOUT=fs而不是預設的 Maildir++ 佈局)。也不要mail_home在全域和使用者數據庫中設置。只需完全刪除該mail_home指令,您的設置不需要它。
  • 因此,您不需要mailbox_command在 Postfix 中使用 a,因為您使用的是虛擬傳輸 ( ),並且在 master.cfvirtual_transport = dovecot中定義了服務。dovecot見下一點。
  • 這些天我會選擇 LMTP 而不是 Dovecot 的 LDA deliver。更容易獲得正確,更好的性能,它甚至可以為您提供廉價的收件人驗證。有關如何實施 LMTP,請參閱http://wiki2.dovecot.org/HowTo/PostfixDovecotLMTP 。
  • 確保 的權限/var/mail/vmail正確。該vmail目錄和所有子目錄應由 UID 5000 和 GID 5000 擁有,其他任何人不得擁有。不要將任何其他使用者放在該組中。

這是我到目前為止可以說的,查看了您的配置和錯誤消息。嘗試解決上述問題,看看你會得到什麼。

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