postfix+mysql(数据库对邮件的管理)
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 [email protected] identified by ‘postuser’; ##建立数据库email本地管理用户postuser ,密码为postuser
grant select,update,insert on email.* to [email protected]; ##授权管理用户
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)测试
[[email protected] postfix]# postmap -q “[email protected]” mysql:/etc/postfix/mailuser.cf
[email protected]
[[email protected] postfix]# postmap -q “lee.com” mysql:/etc/postfix/maildomain.cf
lee.com
[[email protected] postfix]# postmap -q “[email protected]” 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 [email protected]
ls /home/vmail