Dovecot 虚拟用户无法发送/接收邮件

Dovecot 虚拟用户无法发送/接收邮件

几天前,我让 Dovecot + Postfix 与 Squirrelmail 一起运行。不久之后,我厌倦了“Mail for nuts”,转而使用 RainLoop。不过,它似乎运行良好,但仅限于文字用户。虚拟用户可以登录,但无法发送或接收邮件。我四处寻找,但什么也想不通。有一篇帖子指出,这是由于 Postfix 配置中的目的地不是“localhost”,但我仍然遇到同样的问题。

我认为我已经创建了所有需要的帐户。用户数据库位于 vmail 帐户下。

Postfix(main.cf):# 请参阅 /usr/share/postfix/main.cf.dist 以获取带注释的更完整的版本

# Debian specific:  Specifying a file name will cause the first
# line of that file to be used as the name.  The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname

smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

readme_directory = no

# TLS parameters
smtpd_tls_cert_file = /etc/ssl/certs/smtpd.crt
smtpd_tls_key_file = /etc/ssl/private/smtpd.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated 
defer_unauth_destination
myhostname = server1.endev.xyz
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = localhost
relayhost = </code>
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = all
home_mailbox = Maildir/
mailbox_command = 
smtpd_sasl_local_domain = 
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination
smtp_tls_security_level = encrypt
smtpd_tls_security_level = may
smtpd_tls_auth_only = no
smtp_tls_note_starttls_offer = yes
smtpd_tls_CAfile = /etc/ssl/certs/cacert.pem
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
tls_random_source = dev:/dev/urandom

Dovecot(dovecot.conf):

## Dovecot configuration file

# If you're in a hurry, see http://wiki2.dovecot.org/QuickConfiguration

# "doveconf -n" command gives a clean output of the changed settings. Use it
# instead of copy&pasting files when posting to the Dovecot mailing list.

# '#' character and everything after it is treated as comments. Extra spaces
# and tabs are ignored. If you want to use either of these explicitly, put the
# value inside quotes, eg.: key = "# char and trailing whitespace  "

# Most (but not all) settings can be overridden by different protocols and/or
# source/destination IPs by placing the settings inside sections, for example:
# protocol imap { }, local 127.0.0.1 { }, remote 10.0.0.0/8 { }

# Default values are shown for each setting, it's not required to uncomment
# those. These are exceptions to this though: No sections (e.g. namespace {})
# or plugin settings are added by default, they're listed only as examples.
# Paths are also just examples with the real defaults being based on configure
# options. The paths listed here are for configure --prefix=/usr
# --sysconfdir=/etc --localstatedir=/var

# Enable installed protocols
!include_try /usr/share/dovecot/protocols.d/*.protocol

# A comma separated list of IPs or hosts where to listen in for connections. 
# "*" listens in all IPv4 interfaces, "::" listens in all IPv6 interfaces.
# If you want to specify non-default ports or anything more complex,
# edit conf.d/master.conf.
#listen = *, ::

# Base directory where to store runtime data.
#base_dir = /var/run/dovecot/

# Name of this instance. In multi-instance setup doveadm and other commands
# can use -i <instance_name> to select which instance is used (an alternative
# to -c <config_path>). The instance name is also added to Dovecot processes
# in ps output.
#instance_name = dovecot

# Greeting message for clients.
#login_greeting = Dovecot ready.

# Space separated list of trusted network ranges. Connections from these
# IPs are allowed to override their IP addresses and ports (for logging and
# for authentication checks). disable_plaintext_auth is also ignored for
# these networks. Typically you'd specify your IMAP proxy servers here.
#login_trusted_networks =

# Space separated list of login access check sockets (e.g. tcpwrap)
#login_access_sockets = 

# With proxy_maybe=yes if proxy destination matches any of these IPs, don't do
# proxying. This isn't necessary normally, but may be useful if the destination
# IP is e.g. a load balancer's IP.
#auth_proxy_self =

# Show more verbose process titles (in ps). Currently shows user name and
# IP address. Useful for seeing who are actually using the IMAP processes
# (eg. shared mailboxes or if same uid is used for multiple accounts).
#verbose_proctitle = no

# Should all processes be killed when Dovecot master process shuts down.
# Setting this to "no" means that Dovecot can be upgraded without
# forcing existing client connections to close (although that could also be
# a problem if the upgrade is e.g. because of a security fix).
#shutdown_clients = yes

# If non-zero, run mail commands via this many connections to doveadm server,
# instead of running them directly in the same process.
#doveadm_worker_count = 0
# UNIX socket or host:port used for connecting to doveadm server
#doveadm_socket_path = doveadm-server

# Space separated list of environment variables that are preserved on Dovecot
# startup and passed down to all of its child processes. You can also give
# key=value pairs to always set specific settings.
#import_environment = TZ

##
## Dictionary server settings
##

# Dictionary can be used to store key=value lists. This is used by several
# plugins. The dictionary can be accessed either directly or though a
# dictionary server. The following dict block maps dictionary names to URIs
# when the server is used. These can then be referenced using URIs in format
# "proxy::<name>".

dict {
  #quota = mysql:/etc/dovecot/dovecot-dict-sql.conf.ext
  #expire = sqlite:/etc/dovecot/dovecot-dict-sql.conf.ext
}

# Most of the actual configuration gets included below. The filenames are
# first sorted by their ASCII value and parsed in that order. The 00-prefixes
# in filenames are intended to make it easier to understand the ordering.
!include conf.d/*.conf

# A config file can also tried to be included without giving an error if
# it's not found:
!include_try local.conf


# CUSTOM CONFIG #

# Enabled Protocols
protocols = pop3 imap
pop3_uidl_format = %08Xu%08Xv

# Plugins
mail_plugins = $mail_plugins quota

# IMAP Protocol
protocol imap {
    listen = *:143
    ssl_listen = *:993
    imap_client_workarounds = tb-extra-mailbox-sep
    mail_plugins = $mail_plugins imap_quota
}

# POP3 Protocol
protocol pop3 {
    listen = *:110
    ssl_listen = *:995
}

plugin {
    quota = maildir
}

# SSL
ssl = yes
ssl_cert_file = /etc/ssl/certs/ssl-cert-snakeoil.pem
ssl_key_file = /etc/ssl/private/ssl-cert-snakeoil.key


# logs
log_path = /var/log/dovecot.log
info_log_path = /var/log/dovecot-info.log

# Authentication configuration:
auth_verbose = yes
auth_mechanisms = plain

passdb {
  driver = passwd-file
  args = scheme=plain-md5 username_format=%n /home/vmail/dovedb
}
userdb {
  driver = passwd-file
  args = username_format=%n /home/vmail/dovedb
  default_fields = uid=vmail gid=vmail home=/home/vmail/%u
}

protocol lda {
  postmaster_address = [email protected]
}

Dovecot 命令似乎还表明某些设置(例如ssl_cert_file和)ssl_key_file已被弃用,但是,当我用新设置替换它们时,RainLoop 无法进行身份验证。无论如何,我都在考虑切换到 RoundCube,但仍然不确定发生了什么。

虚拟用户数据库(dovedb):

oct:{SSHA}*removed*::::::userdb_quota_rule=*:storage=128M
pf:{SSHA}*removed*::::::userdb_quota_rule=*:storage=128M

答案1

我使用 RoundCube 1.2.2 使其工作,方法如下:

  • 创造自签名 SSL 证书并将其放置在:

    smtpd_tls_cert_file=/etc/ssl/dovecot.crt
    smtpd_tls_key_file=/etc/ssl/dovecot.key
    
  • 此外,vmail 用户/组数量为 5000(virtual_uid_mapsvirtual_gid_maps

  • 创建一个文件/etc/postfix/vhosts并在不同的行中输入每个域名,例如:

    domain1.com
    domain2.com
    domain3.org
    com.net
    
  • 创建一个文件/etc/postfix/virtual并将虚拟用户和域放在不同的行上,即:

    @domain1.com   [email protected]
    @domain2.com   [email protected]
    @domain3.org   [email protected]
    @dom.net       [email protected]
    
    • main.cf下文中,将"FQDN"以下内容替换为您自己的服务器的 FQDN。

内容/etc/postfix/main.cf

home_mailbox = Maildir/
mailbox_command =

smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
biff = no

append_dot_mydomain = no

readme_directory = no

smtpd_tls_security_level = may
smtp_tls_security_level = may
smtp_tls_loglevel = 1
smtpd_tls_loglevel = 1
smtpd_tls_protocols = !SSLv2, !SSLv3

smtpd_tls_cert_file=/etc/ssl/dovecot.crt
smtpd_tls_key_file=/etc/ssl/dovecot.key
smtpd_use_tls=yes

smtpd_relay_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
myhostname = "FQDN"
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = "FQDN", mercury, localhost.localdomain, localhost
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all

virtual_mailbox_domains = /etc/postfix/vhosts
virtual_mailbox_base = /home/vmail
virtual_mailbox_maps = hash:/etc/postfix/vmaps

virtual_minimum_uid = 1000
virtual_uid_maps = static:5000
virtual_gid_maps = static:5000
virtual_alias_maps = hash:/etc/postfix/virtual

milter_protocol = 2
milter_default_action = accept

smtpd_milters = inet:localhost:12301
non_smtpd_milters = inet:localhost:12301

queue_directory = /var/spool/postfix
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth

smtpd_sasl_auth_enable = yes
smtpd_sasl_authenticated_header = yes
broken_sasl_auth_clients = yes

smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_cert_file = /etc/ssl/dovecot.crt
smtp_tls_key_file = /etc/ssl/dovecot.key
smtp_use_tls = yes

内容/etc/postfix/master.cf如下:

smtp      inet  n       -       -       -       -       smtpd
  -o content_filter=spamassassin
submission inet n       -       -       -       -       smtpd
  -o smtpd_tls_security_level=encrypt
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_sasl_type=dovecot
  -o smtpd_sasl_path=private/auth
  -o smtpd_sasl_security_options=noanonymous
  -o smtpd_sasl_local_domain=$myhostname
  -o smtpd_client_restrictions=permit_sasl_authenticated,reject
  -o smtpd_sender_login_maps=hash:/etc/postfix/virtual
  -o smtpd_sender_restrictions=reject_sender_login_mismatch
  -o smtpd_recipient_restrictions=reject_non_fqdn_recipient,reject_unknown_recipient_domain,permit_sasl_authenticated,reject
smtps     inet  n       -       -       -       -       smtpd
  -o syslog_name=postfix/smtps
  -o smtpd_tls_wrappermode=yes
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_client_restrictions=permit_sasl_authenticated,reject
pickup    unix  n       -       -       60      1       pickup
cleanup   unix  n       -       -       -       0       cleanup
qmgr      unix  n       -       n       300     1       qmgr
tlsmgr    unix  -       -       -       1000?   1       tlsmgr
rewrite   unix  -       -       -       -       -       trivial-rewrite
bounce    unix  -       -       -       -       0       bounce
defer     unix  -       -       -       -       0       bounce
trace     unix  -       -       -       -       0       bounce
verify    unix  -       -       -       -       1       verify
flush     unix  n       -       -       1000?   0       flush
proxymap  unix  -       -       n       -       -       proxymap
proxywrite unix -       -       n       -       1       proxymap
smtp      unix  -       -       -       -       -       smtp
relay     unix  -       -       -       -       -       smtp
showq     unix  n       -       -       -       -       showq
error     unix  -       -       -       -       -       error
retry     unix  -       -       -       -       -       error
discard   unix  -       -       -       -       -       discard
local     unix  -       n       n       -       -       local
virtual   unix  -       n       n       -       -       virtual
lmtp      unix  -       -       -       -       -       lmtp
anvil     unix  -       -       -       -       1       anvil
scache    unix  -       -       -       -       1       scache
#
maildrop  unix  -       n       n       -       -       pipe
  flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}
#
# ====================================================================
uucp      unix  -       n       n       -       -       pipe
  flags=Fqhu user=uucp argv=uux -r -n -z -a$sender - $nexthop!rmail ($recipient)
#
# Other external delivery methods.
#
ifmail    unix  -       n       n       -       -       pipe
  flags=F user=ftn argv=/usr/lib/ifmail/ifmail -r $nexthop ($recipient)
bsmtp     unix  -       n       n       -       -       pipe
  flags=Fq. user=bsmtp argv=/usr/lib/bsmtp/bsmtp -t$nexthop -f$sender $recipient
scalemail-backend unix  -       n       n       -       2       pipe
  flags=R user=scalemail argv=/usr/lib/scalemail/bin/scalemail-store ${nexthop} ${user} ${extension}
mailman   unix  -       n       n       -       -       pipe
  flags=FR user=list argv=/usr/lib/mailman/bin/postfix-to-mailman.py
  ${nexthop} ${user}

spamassassin unix -     n       n       -       -       pipe
        user=spamd argv=/usr/bin/spamc -f -e
        /usr/sbin/sendmail -oi -f ${sender} ${recipient}

创建一个文件/etc/dovecot/users并将虚拟用户和密码放在不同的行上,即:

[email protected]:$1$eOnO.zN.$ZleCa/AeffpJaUs7U9uf9/:5000:5000::/var/vmail/domain1.com/info/::
[email protected]:$1$eOnO.zN.$ZleCa/AeffpJaUs7U9uf9/:5000:5000::/var/vmail/domain2.com/info/::
[email protected]:$1$eOnO.zN.$ZleCa/AeffpJaUs7U9uf9/:5000:5000::/var/vmail/domain3.org/info/::
[email protected]:$1$eOnO.zN.$ZleCa/AeffpJaUs7U9uf9/:5000:5000::/var/vmail/dom.net/info/::

$1$eOnO.zN.$ZleCa/AeffpJaUs7U9uf9/运行结果在哪里mkpasswd --hash=md5 password

提示:您可以创建此脚本来运行并创建用户(脚本名称为 dovecot-adduser`):

echo "$username@$domain:`mkpasswd --hash=md5 $2`:5000:5000::/home/vmail/$domain/$username/::" >> /etc/dovecot/users

# create the maildir directory structure
/usr/bin/maildirmake.dovecot /var/vmail/$domain/$username/mail 5000:5000
chown -R vmail:vmail /home/vmail/$domain

# add the user to the Postfix virtual map file
echo $1 $domain/$username/ >> /etc/postfix/vmaps
postmap /etc/postfix/vmaps
postfix reload

然后运行dovecot-adduser username password

其内容/etc/dovecot/dovecot.conf为:

!include_try /usr/share/dovecot/protocols.d/*.protocol
dict {
  #quota = mysql:/etc/dovecot/dovecot-dict-sql.conf.ext
  #expire = sqlite:/etc/dovecot/dovecot-dict-sql.conf.ext
}
!include conf.d/*.conf
base_dir = /var/run/dovecot/
protocols = imap pop3
ssl = no
ssl_cert = /etc/ssl/dovecot.crt
ssl_key = /etc/ssl/dovecot.key
ssl_parameters_regenerate = 24hours
log_path = /var/log/dovecot
info_log_path = /var/log/dovecot.info
verbose_ssl = yes
valid_chroot_dirs = /home/vmail/
auth_mechanisms = plain
auth_verbose = yes

pop3_uidl_format = %g
mail_location = maildir:~/
userdb {
  driver = static
  args = uid=vmail gid=vmail home=/home/vmail/%d/%n
  # 'domain' below is domain.tld
  # %u - user     - full name user@domain
  # %n - username - user part in user@domain
  # %d - domain   - domain part in user@domain
}

此外,不确定是否可以包含在内dovecot.conf,但我有以下内容/etc/dovecot/conf.d/auth-passwdfile.conf.ext

passdb {
  driver = passwd-file
  args = scheme=PLAIN username_format=%u /etc/dovecot/users
}

userdb {
  driver = static
  args = uid=vmail gid=vmail home=/home/vmail/%d/%n
}

我希望我没有错过任何东西。重新启动dovecotpostfix尝试一下。我注意到,当我第一次以新用户身份登录时,一开始会失败。我刷新并重试,它成功了。我怀疑这是因为第一次没有Maildir目录结构并创建了它,而第二次尝试时没有问题。

相关内容