###################################postfix+mysql#####################################

1.安装

yum reinstall postfix.x86_64  -y

 

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 ##接收邮件结尾字符的指定

 

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

systemctl start mariadb

vim /etc/my.cnf

如图七

 postfix+mysql,dovecot+mysql

systemctl restart mariadb

mysql_secure_installation

 

3,在/var/www/html/中,下载phpMyadmin-3.4.0-all-languages.tar.bz2

tar jxf  phpMyadmin-3.4.0-all-languages.tar.bz2

mv phpMyadmin-3.4.0-all-languages/ myadmin

cd myadmin/

cp config.sample.inc.php  config.inc.php

vim config.inc.php

如图八

 postfix+mysql,dovecot+mysql

 

systemctl restart httpd

 

应用:

myadmin软件上,

创建数据库email

email库中,创建表emailuser

如图九

postfix+mysql,dovecot+mysql 

 

4,

mysql -uroot -pwestos   ###创建postuser并进行授权

如图十

 postfix+mysql,dovecot+mysql

 

mysql -upostuser -ppostfix   ##登录postuser

如图十一

postfix+mysql,dovecot+mysql 

 

5,

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

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

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

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

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

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

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

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

 

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

hosts = localhost

user = postuser

password = postfix

dbname = email

table = emailuser

select_field = domian

where_field = domain

 

vim /etc/postfix/mialbox.cf   ##用户邮箱查询

hosts = localhost

user = postuser

password = postfix

dbname = email

table = emailuser

select_field = maildir

where_field = username

 

6,配置postfix

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

[email protected]

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

ling.com

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

/ling.com/ling

 

groupadd -g 666 vmail

useradd -s /sbin/nologin -u 666 vmail -g 666

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

 

 

测试:

在虚拟机中

mail [email protected]

 

 

/home/vmail/ling.com/ling中,查看邮件

如图十二

postfix+mysql,dovecot+mysql



###################################dovecot+mysql######################
1.
安装
yum install dovecot
yum install dovecot-mysql -y  ##dovecot
软件的插件,让此软件可以识别mysql

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的认证方式

##
生成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'
125 user_query = SELECT maildir, 666 AS uid, 666 AS gid FROM emailuser WHEREuse   
rname = '%u'
如图二
postfix+mysql,dovecot+mysql

vim /etc/dovecot/conf.d/10-mail.conf
30 mail_location = maildir:/home/vmail/%d/%n      ##
指定邮箱位置
168 first_valid_uid = 666      ##
邮件文件查询用户身份
175 first_valid_gid = 666
如图

postfix+mysql,dovecot+mysql


systemctl restart dovecot



3
,测试:
yum install telnet -y

telnet 172.25.254.135 110
如图四
postfix+mysql,dovecot+mysqlpostfix+mysql,dovecot+mysql



###############################
邮件空壳##################################


vim /etc/postfix/main.cf
75 myhostname = qq-mail.qq.com
83 mydomain = qq.com
99 myorigin = westos.com       ##
收件方的域名(以westos.com结尾的主机)
113 inet_interfaces = all
164 mydestination =             ##
不接受邮件,只转发
316 relayhost = 172.25.254.135   ##
转发给ip172.25.254.135主机

systemctl restart postfix.service

测试:
如图五,六

postfix+mysql,dovecot+mysql

postfix+mysql,dovecot+mysql




相关文章: