第三本书 postfix&mysql dovecot&mysql

######postfix与mariadb######


yum install httpd php php-mysql mariadb-server -y
第三本书 postfix&mysql dovecot&mysql

systemctl start httpd
systemctl start mariadb
(1)调配数据库
mysql_secure_installation

第三本书 postfix&mysql dovecot&mysql
mysql -uroot -pwestos

create user [email protected] identified by 'postuser';  ##添加postuser用户密码为postuser

第三本书 postfix&mysql dovecot&mysql

grant select,insert,update on email.* to [email protected]   ##为postuser在email库增加权限
第三本书 postfix&mysql dovecot&mysql

调配php数据库,可以在网页上登陆
第三本书 postfix&mysql dovecot&mysql

cd /var/www/html
tar jxf phpMyAdmin_3.4.0-all-languages.tar.bz2 ##解压
mv phpMyAdmin_3.4.0-all-languages/  mysqladmin ##改名为mysqladmin
cd mysqladmin
cp -p config.sample.inc.php  config.inc.php
vim config.inc.php
第三本书 postfix&mysql dovecot&mysql

打开浏览器进入172.25.254.130/mysqladmin调配数据库

第三本书 postfix&mysql dovecot&mysql
调配完成后
(2)调配postfix
cd/etc/postfix


vim /etc/postfix/emailuser.cf ##用户名称查询
hosts = localhost ##数据库所在主机
user = postuser ##登陆数据库的用户
password = postuser ##登陆数据库的密码
dbname = email ##postfix要查询的库的名称
table = emailuser ##postfix要查询的表的名称
select_field = username ##postfix要查询的字段
where_field = username ##用户给定postfix的查询条件
第三本书 postfix&mysql dovecot&mysql

vim /etc/postfix/emaildomian.cf ##用户域名查询
hosts = localhost
user = postuser
password = postuser
dbname = email
table = emailuser
select_field = domain
where_field = domain

第三本书 postfix&mysql dovecot&mysql
vim /etc/postfix/mailbox.cf ##用户邮箱位置查询
hosts = localhost
user = postuser
password = postuser
dbname = email
table = emailuser
select_field = maildir
where_field = username
第三本书 postfix&mysql dovecot&mysql

测试
[[email protected] postfix]# postmap -q "[email protected]" mysql:/etc/postfix/mailuser.cf 
[email protected]
[[email protected] postfix]# postmap -q "zxh.com" mysql:/etc/postfix/maildomain.cf 
zxh.com
[[email protected] postfix]# postmap -q "[email protected]" mysql:/etc/postfix/mailbox.cf
/mnt/zxh.com/zxh

第三本书 postfix&mysql dovecot&mysql\

groupadd -g 666 vmail##建立vmail组 gid=666

useradd -s /sbin/nologin -u 666 vmail -g 666##建立用户uid gid=666,非交互式

第三本书 postfix&mysql dovecot&mysql

postconf -e "virtual_mailbox_base = /home/vmail"##设定虚拟用户的邮件目录
postconf -e "virtual_uid_maps = static:666" ##虚拟用户建立的文件uid
postconf -e "virtual_gid_maps = static:666" ##虚拟用户建立的文件gid
postconf -e "virtual_alias_maps = mysql:/etc/postfix/mailuser.cf"##读取数据库用户
postconf -e "virtual_mailbox_domains = mysql:/etc/postfix/maildomain.cf"##读取数据库域
postconf -e "virtual_mailbox_maps = mysql:/etc/postfix/mailbox.cf"##读取数据库邮箱
第三本书 postfix&mysql dovecot&mysql

进入浏览器更改maildir

第三本书 postfix&mysql dovecot&mysql
测试mail [email protected]
cd /home/vmail/zxh.com/zxh/new




第三本书 postfix&mysql dovecot&mysql
#####dovecot&mysql####
实验前需先配置好westos.com与qq.com两台虚拟机,php
1.
yum install dovecot dovecot-mysql -y  
2.
vim  /etc/dovecot/dovecot.conf
  24 protocols = imap pop3 lmtp ##支持的收件协议
  48 login_trusted_networks = 0.0.0.0/0 ##信任网络
  49 disable_plaintext_auth = no ##开启明文认证
第三本书 postfix&mysql dovecot&mysql

vim /etc/dovecot/conf.d/10-auth.conf
 123 !include auth-sql.conf.ext ##开启mysql的认证方式
第三本书 postfix&mysql dovecot&mysql

#生成dovecot读取mysql的配置
cp /usr/share/doc/dovecot-2.2.10/example-config/dovecot-sql.conf.ext  /etc/dovecot/dovecot-sql.conf.ext


vim  /etc/dovecot/dovecot-sql.conf.ext
  32 driver = mysql ##数据库类型
  71 connect = host=localhost dbname=email user=postuser password=postuser ##查询时用到的库,用户,密码
  78 default_pass_scheme =PLAIN ##默认认证方式为明文
  107 password_query = \ ##查询密码匹配
  108    SELECT  username, domain, password \

  109    FROM emailuser WHERE username = '%u' AND domain = '%d'

第三本书 postfix&mysql dovecot&mysql

  125 user_query = SELECT maildir, 666 AS uid, 666 AS gid FROM emailuser WHERE username = '%u'


vim /etc/dovecot/conf.d/10-mail.conf

  30 mail_location = maildir:/home/vmail/%d/%n ##指定邮件位置

第三本书 postfix&mysql dovecot&mysql

  168 first_valid_uid = 666 ##邮件文件查询用户身份
  175 first_valid_gid = 666


systemctl restart dovecot


测试
[[email protected] network-scripts]# telnet 172.25.254.130 110
Trying 172.25.254.130...
Connected to 172.25.254.130.
Escape character is '^]'.
+OK [XCLIENT] Dovecot ready.
user [email protected]
+OK
pass postuser
+OK Logged in.
第三本书 postfix&mysql dovecot&mysql

在雷鸟中登陆[email protected]查看邮件
第三本书 postfix&mysql dovecot&mysql

####空壳邮箱####
以172.25.254.230 qq.com作为空壳邮箱,在其中
vim  /etc/postfix/main.cf
99 myorigin = westos.com
164 mydestination = 
316 relayhost = 172.25.254.130
第三本书 postfix&mysql dovecot&mysql

systemctl restart postfix
测试
mail root

在172.25.254.130 westos.com中可收到测试邮件

第三本书 postfix&mysql dovecot&mysql