Centos

Dovecot 創建文件夾,Postfix 需要文件

  • March 7, 2014

我嘗試使用本指南為虛擬使用者配置 Postfix/Dovecot 組合。

我的伺服器在 CentOS 6.5 上執行 Postfix 2.6.6 和 Dovecot 2.0.9。

問題是當我使用 Outlook 2013 連接到伺服器(它在 IMAP+SMTP 上連接得很好)並向自己發送一封測試電子郵件時,我沒有收到電子郵件。查看郵件日誌,我可以看到我收到了錯誤

postfix/virtual[2768]: 9C3D480768: to=<user@domain.net>, relay=virtual, delay=1132, delays=1132/0.02/0/0.02, dsn=4.2.0, status=deferred (delivery failed to mailbox /var/vmail/domain.net/user: cannot open file: Is a directory)

錯誤消息很清楚,我想,這可能是我之前安裝的有缺陷的 Cyrus/Postfix 的遺留物。我繼續刪除了 vmail 文件夾,為域創建了一個子文件夾,並將所有內容的所有權更改為 vmail:vmail。我重新啟動 postfix 和 dovecot,收件箱目錄再次出現。Postfix 繼續像以前一樣抱怨。然後我嘗試刪除該文件夾,然後創建一個空文件,但這只會使其成為 dovecot 問題而不是 postfix 問題,所以現在 dovecot 說它需要一個文件而不是目錄。

/etc/postfix/main.cf

queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
mail_owner = postfix
unknown_local_recipient_reject_code = 550
alias_maps = hash:/etc/postfix/aliases
alias_database = $alias_maps

inet_interfaces = all
inet_protocols = ipv4
mydestination = $myhostname, localhost.$mydomain, localhost

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/sbin/sendmail.postfix
newaliases_path = /usr/bin/newaliases.postfix
mailq_path = /usr/bin/mailq.postfix
setgid_group = postdrop
html_directory = no
manpage_directory = /usr/share/man
sample_directory = /usr/share/doc/postfix-2.6.6/samples
readme_directory = /usr/share/doc/postfix-2.6.6/README_FILES

relay_domains = *
virtual_alias_maps=hash:/etc/postfix/vmail_aliases
virtual_mailbox_domains=hash:/etc/postfix/vmail_domains
virtual_mailbox_maps=hash:/etc/postfix/vmail_mailbox

virtual_mailbox_base = /var/vmail
virtual_minimum_uid = 2222
virtual_transport = virtual
virtual_uid_maps = static:2222
virtual_gid_maps = static:2222

smtpd_sasl_auth_enable = yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = /var/run/dovecot/auth-client
smtpd_sasl_security_options = noanonymous
smtpd_sasl_tls_security_options = $smtpd_sasl_security_options
smtpd_sasl_local_domain = $mydomain
broken_sasl_auth_clients = yes

smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
smtpd_relay_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination

/etc/dovecot/dovecot.conf

listen = *
ssl = no
protocols = imap lmtp
disable_plaintext_auth = no
auth_mechanisms = plain login
mail_access_groups = vmail
default_login_user = vmail
first_valid_uid = 2222
first_valid_gid = 2222
mail_location = maildir:/var/vmail/%d/%n

passdb {
   driver = passwd-file
   args = scheme=SHA1 /etc/dovecot/passwd
}
userdb {
   driver = static
   args = uid=2222 gid=2222 home=/var/vmail/%d/%n allow_all_users=yes
}
service auth {
   unix_listener auth-client {
       group = postfix
       mode = 0660
       user = postfix
   }
   user = root
}
service imap-login {
   process_min_avail = 1
   user = vmail
}

最後是我的域/別名/郵箱列表中的一些範例條目

domain.tld        OK # /etc/postfix/vmail_domains
user@domain.tld   domain.tld/user # /etc/postfix/vmail_mailbox
user@domain.tld   user@domain.tld # /etc/postfix/vmail_aliases
user@domain.tld:oOeIaLM/TyEPOdflb+GlL7d1MhE= # /etc/dovecot/passwd

答案非常簡單。中的路徑/etc/postfix/vmail_mailbox缺少尾部斜杠。當沒有尾部斜杠時,postfix 會將其視為一個文件,從而假定郵箱是 Mailbox(而不是 Maildir)格式。

通過附加斜杠,postfix 將正確地認為目錄是 maildir 格式並相應地對待它。

例子:

user@domain.tld   domain.tld/user/
user2@domain.tld   domain.tld/user2/

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