邮件服务postfix+mysql

                                                                          ---------------postfix+mysql------------

postfix(作为发送邮件服务器)+mysql(作为数据库):

Postfix+mysql主要是把邮件服务的发与mysql结合使用,再以php的格式结合Apache通过网页的形式管理mysql。

[[email protected] ~]# mv /etc/postfix/main.cf /mnt/        ######将之前postfix的主配置文件备份
[[email protected] ~]# yum reinstall postfix.x86_64 -y    #####重新下载安装软件
[[email protected] ~]# vim  /etc/postfix/main.cf                 #####修改主配置文件

76 myhostname = westos-mail.westos.com        ####指定mta主机名称
83 mydomain = westos.com   ##指定mta的域名
99 myorigin = westos.com      ##指定邮件来源结尾(@后面的字符内容)
116  inet_interfaces = all            ####25端口开启的网络接口
164 mydestination = $myhostname, $mydomain, localhost       ##接收邮件结尾字符的指定

[[email protected] ~]# systemctl restart postfix.service  ######重启服务
[[email protected] ~]# yum install httpd php php-mysql mariadb-server -y    #####下载安装httpd,php,php-masql,mariadb-server
[[email protected] ~]# systemctl start mariadb               #####开启数据库服务
[[email protected] ~]# vim /etc/my.cnf                               ####修改文件,关闭数据库的网络连接

邮件服务postfix+mysql

[[email protected] ~]# systemctl restart mariadb                                   #####重启数据库服务
[[email protected] ~]# systemctl restart postfix.service             #####重启postfix服务
[[email protected] ~]# mysql_secure_installation                       ####mysql安全配置

邮件服务postfix+mysql

[[email protected] html]# tar jxf phpMyAdmin-3.4.0-all-languages.tar.bz2     #####php安装包解压
[[email protected] html]# ls
phpMyAdmin-3.4.0-all-languages
[[email protected] html]# mv phpMyAdmin-3.4.0-all-languages/ myadmin        ####将解压目录重命名

邮件服务postfix+mysql


[[email protected] html]# cd myadmin
[[email protected] myadmin]# ls
[[email protected] myadmin]# cp config.sample.inc.php config.inc.php      #####复制模板
[[email protected] myadmin]# vim config.inc.php        

邮件服务postfix+mysql

[[email protected] myadmin]# systemctl restart httpd          #####重启httpd服务

创建数据库email,添加表emailuser,插入字段及内容

邮件服务postfix+mysql

邮件服务postfix+mysql

邮件服务postfix+mysql

邮件服务postfix+mysql


[[email protected] myadmin]# mysql -uroot -plee            ####root用户登录数据库
MariaDB [(none)]> create user [email protected] identified by 'postuser';         ###创建并认证用户,数据库本地管理用户postuser ,密码为postuser

MariaDB [(none)]> grant select,update,insert on email.* to [email protected];    #####用户授权
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> quit
Bye

邮件服务postfix+mysql

  
[[email protected] myadmin]# mysql -upostuser -ppostuser     ####postuser用户登录,查看创建数据库的所有内容

邮件服务postfix+mysql
配置postfix服务

[[email protected] ~]# cd /etc/postfix/
[[email protected] postfix]# vim mailuser.cf   ####用户名称查询
hosts = localhost                      ####数据库所在主机
user = postuser                        ####登录数据库的用户
password = postuser              ####登录数据库的密码
dbname = email                       ####postfix要查询的数据库名称
table = emailuser                     ####postfix要查询的表的名称
select_field = username        ###postfix要查询的字段
where_field = username        ###用户给定postfix的查询字段

邮件服务postfix+mysql
[[email protected] postfix]# postmap -q "[email protected]" mysql:/etc/postfix/mailuser.cf      ###检查文件书写是否正确
[email protected]
[[email protected] postfix]# cp  mailuser.cf maildomain.cf
[[email protected] postfix]# vim  maildomain.cf      ####用户域名查询

邮件服务postfix+mysql

[[email protected] postfix]# postmap -q "lee.com" mysql:/etc/postfix/maildomain.cf
lee.com
[[email protected] postfix]# cp  mailuser.cf mailbox.cf
[[email protected] postfix]# vim  mailbox.cf             ####用户邮箱位置查询

邮件服务postfix+mysql

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

邮件服务postfix+mysql
[[email protected] ~]# groupadd -g 666 vmail                                           ####建立gid为666的组
[[email protected] ~]# useradd -s /sbin/nologin -u 666 vmail -g 666    ####添加虚拟用户,uid为666
[[email protected] ~]# id vmail
uid=666(vmail) gid=666(vmail) groups=666(vmail)
[[email protected] ~]# cd /home/vmail                      ####基本配置路径
[[email protected] vmail]# ls
mail
[[email protected] vmail]# postconf -e "virtual_mailbox_base = /home/vmail"    #####设定虚拟用户的邮件目录
[[email protected] vmail]# postconf -e "virtual_uid_maps = static:666"                ####虚拟用户建立文件的uid
[[email protected] vmail]# postconf -e "virtual_gid_maps = static:666"                ####虚拟用户建立文件的gid
[[email protected] vmail]# postconf -e "virtual_alias_maps = mysql:/etc/postfix/mailuser.cf"  ###使数据库中信息与postfix关联
[[email protected] vmail]# postconf -e "virtual_mailbox_maps = mysql:/etc/postfix/mainbox.cf"
[[email protected] vmail]# postconf -e "virtual_mailbox_domains = mysql:/etc/postfix/maindomain.cf"
[[email protected] vmail]# systemctl restart postfix                       #####重启postfix服务

----在数据库email中修改maildir信息   /lee.com/lee/

邮件服务postfix+mysql

----邮箱的基本配置路径为/home/vmail


[[email protected] vmail]# ll /etc/postfix/mailuser.cf                  #####查看是否生成文件
-rw-r--r--. 1 root root 134 May 21 04:10 /etc/postfix/mailuser.cf
[[email protected] vmail]# ll /etc/postfix/maindomain.cf
-rw-r--r--. 1 root root 130 May 21 04:12 /etc/postfix/maindomain.cf[[email protected] vmail]# cd /home/vmail/

测试:

[[email protected] vmail]# mail [email protected]
Subject: djsd
dbha
.
EOT
[[email protected] vmail]# ls
lee.com  mail
[[email protected] vmail]# cd lee.com/
[[email protected] lee.com]# ls
lee
[[email protected] lee.com]# cd lee/
[[email protected] lee]# ls
cur  new  tmp
[[email protected] lee]# cd new/
[[email protected] new]# ls
1495357308.Vfd01I1a9eeefM765586.qq-mail.qq.com
1495357369.Vfd01I1a9eef0M465476.qq-mail.qq.com
[[email protected] new]# cat new/1495357308.Vfd01I1a9eeefM765586.westos-mail.westos.com

邮件服务postfix+mysql