使用 dovecot + postfix 设置无法接收邮件

使用 dovecot + postfix 设置无法接收邮件

第一次在运行最新 Ubuntu 的机器上设置自己的邮件服务器

经过一番寻找,我决定使用 dovecot + postfix 和虚拟用户,邮箱位于 /var/mail/vmail/%d/%n

在大多数情况下,我遵循收回电子邮件找到教程系列这里

我注意到当我尝试通过 IMAP 连接到[电子邮件保护]创建了正确的目录结构,因此 /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 的所有内容都打开了详细模式,但从我得到的日志中我无法确定问题的确切来源。

这是我的 postfix master.cf 的相关部分

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

非常感谢任何形式的帮助或建议

更新 1

事实证明,postfix 中有一个 mailbox_command 没有正确设置,因此我将其从

#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的内容为:

[email protected]       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 = [email protected]
  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

答案1

首先,您的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)

mailbox_command这是因为 Postfix 尝试使用(Dovecot 的 LDA )作为接收消息的用户(dany)来传递邮件deliver,但该用户当然无权写信,/var/mail/vmail因为它是虚拟用户。

我假设您需要合适的虚拟邮件托管,例如在http://www.postfix.org/VIRTUAL_README.html

  • 您的 Dovecotmail_location设置应该就是这样mail_location = maildir:~/mail:LAYOUT=fs(问问自己是否真的想要LAYOUT=fs而不是默认的 Maildir++ 布局)。另外,不要mail_home同时在全局和 userdb 中设置。只需mail_home完全删除该指令,它对于您的设置来说不是必需的。

  • mailbox_command因此,由于您使用的是虚拟传输(virtual_transport = dovecot)并且已在 master.cf 中定义了服务,因此您不需要Postfix dovecot。请参阅下一点。

  • 现在我会使用 LMTP 而不是 Dovecot 的 LDA deliver。更容易正确使用,性能更好,甚至可以以低廉的价格为您提供收件人验证。请参阅http://wiki2.dovecot.org/HowTo/PostfixDovecotLMTP如何实施 LMTP。

  • 确保的权限/var/mail/vmail正确。vmail目录和所有子目录应由 UID 5000 和 GID 5000 拥有,其他用户不得拥有。不要将任何其他用户放入该组中。

这是我查看了您的配置和错误消息后目前能说的。尝试修复上述问题,看看会有什么效果。

答案2

连接到 Milter 服务unix:/clamav/clamav-milter.ctl:权限被拒绝

ls -l /var/spool/postfix/clamav srw-rw---- 1 clamav clamav 0 Apr 4 17:59 clamav-milter.ctl

clamav-milter配置文件

user clamav MilterSocketGroup postfix MilterSocketMode 660

邮件客户端的用户权限

chown postfix:postfix /var/spool/postfix/clamav/clamav-milter.ctl

对我有用。

相关内容