postfix + mariadb

1.安装

yum install httpd php php-mysql mariadb-server -y                         

postfix + mariadb


2.配置mysql

(1)编辑配置文件

vim /etc/my.cnf

postfix + mariadb

skip-networking=1                      ##跳过网络,是

postfix + mariadb


(2)mysql加密

postfix + mariadb


(3)安装网页管理所需工具并配置

解压:

postfix + mariadb


解压后将其改名为mysqladmin:

复制样板配置文件后编辑

postfix + mariadb


postfix + mariadb


3.添加数据库与表

(1)登录后添加数据库email

(2)在数据库email里添加数据表emailuser

postfix + mariadb


(3)在数据表中添加username,password,domain,maildir这四个字段,类型都为VARCHAR

postfix + mariadb


(4)在emailuser表中添加值如下图:

postfix + mariadb


(5)创建用户并授权

create user [email protected] identified by 'postfix'                                ##创建数据库用户[email protected],密码为postuser

grant select,update,insert on email.* to [email protected]              ##为用户postuser授权

postfix + mariadb


(6)登入postuser,查看emailuser表内容

postfix + mariadb



3.配置postfix

vim /etc/postfix/mailuser.cf                          ##用户名查询

postfix + mariadb


postfix + mariadb

##

hosts = localhost                    ##数据库所在主机

user = postuser                    ##登录数据库的用户

password = postuser          ##登录数据库的密码

dbname = email                   ##postfix要查询数据库的名称

table = emailuser                 ##postfix要查询数据表的名称

select_field = username    ##postfix要查询的字段

where_field = username    ##用户给定postfix的查询条件


vim maildomain.cf                           ##用户域名查询

postfix + mariadb


postfix + mariadb

##

hosts = localhost

user = postuser

password = postuser

dbname = email

table = emailuser

select_field = domain                  ##给定查询字段为domain

where_field = domain


vim mailbox.cf                            ##用户邮箱位置查询

postfix + mariadb


postfix + mariadb

##

hosts = localhost

user = postuser

password = postuser

dbname = email

table = emailuser

select_field = maildir                   ##给定要查询字段为maildir

where_field = username


测试:

postmap -q "[email protected]" mysql:/etc/postfix/mailuser.cf

postmap -q "lk.com" mysql:/etc/postfix/maildomain.cf  

postmap -q "[email protected]" mysql:/etc/postfix/mailbox.cf  

postfix + mariadb


4.添加用户vmail

groupadd -g 666 vmail                       ##新建组vmail指定gid为666

useradd -s /sbin/nologin  -u 666 vmail -g 666                     ##新建用户vmail所使用shell为/sbin/nllogin,指定uid和gid都为666

postfix + mariadb


5.配置postfix

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"                            ##指定mysql查找主机名

postconf -e "virtual_mailbox_domains = mysql:/postfix/maildomain.cf"                 ##指定mysql查找域名

postconf -e "virtual_mailbox_maps = mysql:/etc/postfix/mailbox.cf"                        ##指定mysql查找邮件目录

postfix + mariadb


测试:

postfix + mariadb

效果:

postfix + mariadb