4. Dovecot
Postfix比作邮局, Dovecot就是邮局管家.提供用户合法认证, 对外提供POP, IMAP 服务.这样常用的电邮客户端就能连入邮局,收发和管理信件.电邮相关软件,一律放在/opt/tsMail文件夹下,方便布署,还能尽可能不污染当前的操作系统环境.我们用的Dovecot 2.3.17,来自官网
https://www.dovecot.org/ 源码下载,编译而成,以保证目前(2022.01.05)具最新功能.
1. 新建用户和组
sudo groupadd -g 5000 vmail
sudo useradd -g vmail -u 5000 vmail -d /opt/tsMail/var/mail
groupadd -g 1012 dovecot &&
useradd -c "Dovecot unprivileged user" -d /dev/null -u 1012 \
-g dovecot -s /bin/false dovecot &&
groupadd -g 1013 dovenull &&
useradd -c "Dovecot login user" -d /dev/null -u 1013 \
-g dovenull -s /bin/false dovenull
2. 文件目录及权限
sudo mkdir -p /opt/tsMail/var/mail/vhosts/otherhill.com
sudo chown -R vmail:vmail /opt/tsMail/var/mail
sudo chown -R vmail:dovecot /opt/tsMail/etc/dovecot
chmod -R o-rwx /opt/tsMail/etc/dovecot
3. Dovecot 配置文件
a). /opt/tsMail/etc/dovecot/dovecot.conf
listen = *,::
#submission
protocols = imap imaps pop3 pop3s lmtp
log_path = /var/log/dovecot.log
log_timestamp = "%Y-%m-%d %H:%M:%S "
!include conf.d/*.conf
verbose_ssl = yes
b). /opt/tsMail/etc/dovecot/conf.d/10-auth.conf
auth_debug = yes
auth_debug_passwords = yes
#cram-md5
auth_mechanisms = plain login
disable_plaintext_auth = yes
auth_verbose = yes
ssl = yes
!include auth-sql.conf.ext
c). /opt/tsMail/etc/dovecot/conf.d/auth-sql.conf.ext
passdb {
driver = sql
args = /opt/tsMail/etc/dovecot/dovecot-sql.conf.ext
}
userdb {
driver = static
args = uid=vmail gid=vmail home=/opt/tsMail/var/mail/vhosts/%d/%n
}
d). /opt/tsMail/etc/dovecot/dovecot-sql.conf.ext
#https://www.linode.com/docs/guides/email-with-postfix-dovecot-and-mysql/
driver = mysql
connect = host=127.0.0.1 dbname=ts_mail user=root password=your_mysql_password
default_pass_scheme = SHA512-CRYPT
password_query = SELECT email as user, password FROM virtual_users WHERE email='%u';
e). /opt/tsMail/etc/dovecot/conf.d/10-mail.conf
mail_location = maildir:/opt/tsMail/var/mail/vhosts/%d/%n/
mail_privileged_group = mail
mail_plugins = $mail_plugins quota
f). /opt/tsMail/etc/dovecot/conf.d/10-master.conf
service imap-login {
inet_listener imap {
#port = 143
port = 4147
}
inet_listener imaps {
#port = 993
port = 4150
ssl = yes
}
}
service pop3-login {
inet_listener pop3 {
#port = 110
port = 4146
}
inet_listener pop3s {
#port = 995
port = 4151
ssl = yes
}
}
service lmtp {
unix_listener /opt/tsMail/var/spool/postfix/private/dovecot-lmtp {
mode = 0666
user = postfix
group = postfix
}
}
service quota-status {
executable = quota-status -p postfix
inet_listener {
port = 12340
# You can choose any port you want
}
client_limit = 1
}
service auth {
unix_listener /opt/tsMail/var/spool/postfix/private/auth {
mode = 0660
user = postfix
group = postfix
}
unix_listener auth-userdb {
mode = 0600
user = vmail
}
user = dovecot
}
service auth-worker {
user = vmail
}
g). /opt/tsMail/etc/dovecot/conf.d/10-ssl.conf
ssl = required
ssl_cert = </opt/ssl/otherhill.com/fullchain.pem
ssl_key = </opt/ssl/otherhill.com/privkey.pem
ssl_min_protocol = TLSv1.2
ssl_protocols = !SSLv3 !TLSv1 !TLSv1.1
ssl_cipher_list = TLS13-AES-128-GCM-SHA256:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-RSA-AES256-GCM-SHA384:AES128-SHA:AES256-SHA:RC4-SHA:DES-CBC3-SHA:RC4-MD5
h). /opt/tsMail/etc/dovecot/conf.d/20-imap.conf
protocol imap {
# Space separated list of plugins to load (default is global mail_plugins).
mail_plugins = $mail_plugins imap_quota
}
i). /opt/tsMail/etc/dovecot/conf.d/20-lmtp.conf
protocol lmtp {
postmaster_address = postmaster@otherhill.com # required
hostname=mail.otherhill.com
}
j). /opt/tsMail/etc/dovecot/conf.d/90-quota.conf
plugin {
quota = count:User quota
quota_max_mail_size = 100M
# Required for 'count' quota driver
quota_vsizes = yes
quota_rule = *:storage=1G
quota_rule2 = Trash:storage=+100M
# LDA/LMTP allows saving the last mail to bring user from under quota to
# over quota, if the quota doesn't grow too high. Default is to allow as
# long as quota will stay under 10% above the limit. Also allowed e.g. 10M.
quota_grace = 10%%
# Quota plugin can also limit the maximum accepted mail size.
quota_max_mail_size = 100M
}
plugin {
quota_status_success = DUNNO
quota_status_nouser = DUNNO
quota_status_overquota = "552 5.2.2 Mailbox is full"
}
设置用户邮箱容量为1G
4. Dovecot 常用命令行
a).查看当前配置
dovecot -c /opt/tsMail/etc/dovecot/dovecot.conf
b).显示指定帐户容量配额
doveadm quota get -u i@otherhill.com
c).启动,关闭与重载
dovecot -c /opt/tsMail/etc/dovecot/dovecot.conf
dovecot -c /opt/tsMail/etc/dovecot/dovecot.conf stop
dovecot -c /opt/tsMail/etc/dovecot/dovecot.conf reload
d).查看远程端口打开情况:
nmap mail.otherhill.com
e).查看本地端口打开情况:
netstat -tnla
f).查看dovecot打开端口情况:
[root@localhost postfix]# ss -lnpt | grep dovecot