postfix+mysql(数据库对邮件的管理)

来源:互联网 发布:知润山产权问题 编辑:程序博客网 时间:2024/06/07 04:06

1.数据库基础设置

yum install httpd php php-mysql.x86_64 mariadb-server.x86_64 -y
mv /etc/postfix/main.cf /mnt ##备份配置文件
yum reinstall postfix.x86_64 ##重新下载
vim /etc/postfix/main.cf ##编辑主配置文件
systemctl restart postfix.service
systemctl start mariadb
mysql_secure_installation ##数据库安全证书初始化
这里写图片描述
tar jxf phpMyAdmin-3.4.0-all-languages.tar.bz2 -C /var/www/html/
rm *.bz2 -f
mv phpMyAdmin-3.4.0-all-languages/ admin/
cp /var/www/html/admin/config.sample.inc.php /var/www/html/admin/config.sample.php
vim /var/www/html/admin/config.sample.php
vim /etc/my.cnf
systemctl restart mariadb
systemctl restart httpd
这里写图片描述
—–web建立表格
mysql -uroot -pwestos
新建库email 在email库新建表emailuser
这里写图片描述

这里写图片描述

这里写图片描述

create user postuser@localhost identified by ‘postuser’; ##建立数据库email本地管理用户postuser ,密码为postuser
grant select,update,insert on email.* to postuser@localhost; ##授权管理用户
这里写图片描述

2.设置postfix

(1)用户名查询
vim /etc/postfix/mailuser.cf ##用户名查询
hosts = localhost ##数据库所在主机
user = postuser ##登陆数据库的用户
password = postuser ##登陆数据库的用户的密码
dbname = email ##postfix要查询的库名称
table = emailuser ##postfix要查询的表的名称
select_field = username ##postfix要查询的字段
where_field = username ##用户给定的postfix的查询条件
这里写图片描述
(2)用户域名查询
vim /etc/postfix/maildomain.cf ##用户域名查询
hosts = localhost
user = postuser
password = postuser
dbname = email
table = emailuser
select_field = domain
where_field = domain
这里写图片描述
(3)用户邮箱位置查询
vim /etc/postfix/mailbox.cf ##用户邮箱位置查询
hosts = localhost
user = postuser
password = postuser
dbname = email
table = emailuser
select_field = maildir
where_field = username
这里写图片描述

这里写图片描述

(4)测试
[root@westos-mail postfix]# postmap -q “lee@lee.com” mysql:/etc/postfix/mailuser.cf
lee@lee.com
[root@westos-mail postfix]# postmap -q “lee.com” mysql:/etc/postfix/maildomain.cf
lee.com
[root@westos-mail postfix]# postmap -q “lee@lee.com” mysql:/etc/postfix/mailbox.cf
/lee.com/lee/
这里写图片描述

3.配置postfix

(1)
groupadd -g 666 vmail ##建立gid为666的组
useradd -s /sbin/nologin -u 666 vmail -g 666 ##建立用于系统登陆的用户
这里写图片描述
(2)
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” ##用户邮箱位置
systemctl restart postfix.service
这里写图片描述

这里写图片描述
(3)测试
mail lee@lee.com
这里写图片描述
ls /home/vmail
这里写图片描述

原创粉丝点击