本章主要介绍使用虚拟用户结合"passwd-file"搭建邮件服务器,测试虚拟域名为myzdl.top,配置如下:
环境:Centos7 + Postfix + Dovecot (passwd-file)
0、需要一个系统用户vmail作为收发邮件的账户,也就是说所有的邮件都是这个vmail用户的
[root@kp ~]# groupadd -g 5000 vmail
[root@kp ~]# useradd -g 5000 -u 5000 vmail
1、为了方便理解,我先配置Dovecot服务,并保证服务正常
[root@kp ~]# yum install dovecot -y
[root@kp ~]# cat /etc/dovecot/dovecot.conf | grep -v ^# | grep -v ^$ #编辑配置文件如下
protocols = imap pop3
listen = 172.16.0.4
log_path = /var/log/dovecot.log
info_log_path = /var/log/dovecot-info.log
auth_verbose = yes
auth_mechanisms = plain
passdb {
driver = passwd-file
args = /etc/dovecot/passwd-users-auth
}
userdb {
driver = static
args = uid=vmail gid=vmail home=/home/vmail/%u
}
dict {
#quota = mysql:/etc/dovecot/dovecot-dict-sql.conf.ext
#expire = sqlite:/etc/dovecot/dovecot-dict-sql.conf.ext
}
!include conf.d/*.conf
!include_try local.conf
取消/etc/dovecot/conf.d/10-mail.conf文件如下行的注释,大概第24行
mail_location = maildir:~/Maildir
注释/etc/dovecot/conf.d/10-auth.conf如下行,取消本地用户登录邮箱,大概第123行
#!include auth-system.conf.ext
2、创建虚拟账号并启动服务:
[root@kp ~]# vim /etc/dovecot/passwd-users-auth
tom@myzdl.top:{plain}pass123::::::
bill@myzdl.top:{plain}bill123::::::
jond@myzdl.top:{plain}asd123::::::
bosl@myzdl.top:{plain}a123456::::::
取消ssl连接方便账号测试登录:
[root@kp ~]# vim /etc/dovecot/conf.d/10-ssl.conf
#ssl = required
ssl = no
[root@kp ~]# vim /etc/dovecot/conf.d/10-auth.conf
#disable_plaintext_auth = yes
disable_plaintext_auth = no
[root@kp ~]# systemctl start dovecot
3、测试账号登录正常,且/home/vmail下有用户邮箱账号
[root@kp ~]# ls -ls /home/vmail/
total 8
4 drwx------ 3 vmail vmail 4096 Jul 15 16:51 bill@myzdl.top
4 drwx------ 3 vmail vmail 4096 Jul 15 16:49 tom@myzdl.top
[root@kp ~]# ls -ld /home/vmail/bill@myzdl.top/*
drwx------ 5 vmail vmail 4096 Jul 15 16:51 /home/vmail/bill@myzdl.top/Maildir
[root@kp ~]# ls -ld /home/vmail/tom@myzdl.top/*
drwx------ 5 vmail vmail 4096 Jul 15 16:49 /home/vmail/tom@myzdl.top/Maildir
4、设置Postfix的smtp-auth,取消/etc/dovecot/conf.d/10-master.conf如下的注释,大概第96行。主要用于提供给postfix服务的smtp认证。
unix_listener /var/spool/postfix/private/auth {
mode = 0666
}
[root@kp ~]# systemctl restart dovecot
[root@kp ~]# cd /etc/postfix/
[root@kp postfix]# vim vmail_domains #一行一个虚拟域名,左边虚拟域名,右边随意写
myzdl.top ok
[root@kp postfix]# vim vmail_mailbox #定义每一个虚拟用户邮件的存放位置,如下省去了根/home/vmail/,原因是主配置文件virtual_mailbox_base = /home/vmail 参数。注意后面"/"
tom@myzdl.top tom@myzdl.top/Maildir/
bill@myzdl.top bill@myzdl.top/Maildir/
jond@myzdl.top jond@myzdl.top/Maildir/
bosl@myzdl.top bosl@myzdl.top/Maildir/
[root@kp postfix]# postmap vmail_domains vmail_mailbox
修改主配置文件main.cf,主要参数如下
myhostname = localhost
#mydomain = domain.tld
myorigin = $myhostname
#mydestination = $myhostname, localhost.$mydomain, localhost
inet_interfaces = all
mynetworks = 127.0.0.0/8
home_mailbox = Maildir/
smtpd_banner = $myhostname ESMTP
smtpd_sasl_type = dovecot
smtpd_sasl_auth_enable = yes
broken_sasl_auth_clients = yes
smtpd_sasl_path = private/auth
virtual_mailbox_base = /home/vmail
virtual_mailbox_domains = hash:/etc/postfix/vmail_domains
virtual_mailbox_maps = hash:/etc/postfix/vmail_mailbox
virtual_transport = virtual
virtual_uid_maps = static:5000
virtual_gid_maps = static:5000
[root@kp ~]# systemctl restart postfix
postfix发送QQ邮件日志:
Jul 15 18:42:27 kp postfix/smtpd[2548]: connect from unknown[183.17.229.135]
Jul 15 18:42:27 kp postfix/smtpd[2548]: 82CD94023C: client=unknown[183.17.229.135], sasl_method=PLAIN, sasl_username=bill@myzdl.top
Jul 15 18:42:27 kp postfix/cleanup[2551]: 82CD94023C: message-id=2020071518422765092114@myzdl.top
Jul 15 18:42:27 kp postfix/qmgr[2423]: 82CD94023C: from=bill@myzdl.top, size=2591, nrcpt=1 (queue active)
Jul 15 18:42:27 kp postfix/smtpd[2548]: disconnect from unknown[183.17.229.135]
Jul 15 18:42:29 kp postfix/smtp[2552]: 82CD94023C: to=2913478900@qq.com, relay=mx3.qq.com[58.251.110.111]:25, delay=1.9, delays=0.05/0.01/0.22/1.6, dsn=2.0.0, status=sent (250 Ok: queued as )
Jul 15 18:42:29 kp postfix/qmgr[2423]: 82CD94023C: removed
postfix接收QQ邮件日志:
Jul 15 18:43:43 kp postfix/smtpd[2548]: connect from smtpbg518.qq.com[203.205.250.104]
Jul 15 18:43:44 kp postfix/smtpd[2548]: 4EAF54023C: client=smtpbg518.qq.com[203.205.250.104]
Jul 15 18:43:45 kp postfix/cleanup[2551]: 4EAF54023C: message-id=tencent_3E4E7D362501323D4D3391B8C9ECE1BCBA0A@qq.com
Jul 15 18:43:45 kp postfix/qmgr[2423]: 4EAF54023C: from=2913478900@qq.com, size=2686, nrcpt=1 (queue active)
Jul 15 18:43:45 kp postfix/virtual[2589]: 4EAF54023C: to=bill@myzdl.top, relay=virtual, delay=1.8, delays=1.7/0.02/0/0, dsn=2.0.0, status=sent (delivered to maildir)
Jul 15 18:43:45 kp postfix/qmgr[2423]: 4EAF54023C: removed
Jul 15 18:43:46 kp postfix/smtpd[2548]: disconnect from smtpbg518.qq.com[203.205.250.104]
最后开启ssl连接:
[root@kp ~]# vim /etc/dovecot/conf.d/10-ssl.conf
ssl = required
[root@kp ~]# vim /etc/dovecot/conf.d/10-auth.conf
#disable_plaintext_auth = yes