#######postfix+mysql#############
配置数据库
[root@maillinux ~]# yum install mariadb-server httpd php php-mysql -y
[root@maillinux ~]# systemctl start mariadb
[root@maillinux ~]# vim /etc/my.cnf
10 skip-networking=1 ##跳过网络验证
[root@maillinux ~]# mysql_secure_installation
[root@maillinux html]# tar jxf phpMyAdmin-3.4.0-all-languages.tar.bz2
[root@maillinux html]# mv phpMyAdmin-3.4.0-all-languages mysqladmin
[root@maillinux html]# cd mysqladmin/
[root@maillinux mysqladmin]# cp config.sample.inc.php config.inc.php
[root@maillinux mysqladmin]# systemctl restart httpd
[root@maillinux mysqladmin]# mysql -uroot -p ##root用户登录数据库
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 41
Server version: 5.5.35-MariaDB MariaDB Server
Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> CREATE USER postfix@localhost identified by 'postfix'; ##创建用户
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> GRANT INSERT,SELECT on email.* to postfix@localhost; ##授权
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> quit;
Bye
******给数据库中的用户发送邮件***********
[root@maillinux mysqladmin]# cd /etc/postfix/
[root@maillinux postfix]# vim mysql-user.cf
hosts = localhost
user = postfix
password = postfix
dbname = email
table = mailuser
select_field = username
where_field = username
[root@maillinux postfix]# cp mysql-user.cf mysql-domain.cf
[root@maillinux postfix]# cp mysql-user.cf mysql-mailbox.cf
[root@maillinux postfix]# vim mysql-domain.cf
hosts = localhost
user = postfix
password = postfix
dbname = email
table = mailuser
select_field = domain
where_field = domain
[root@maillinux postfix]# vim mysql-mailbox.cf
hosts = localhost
user = postfix
password = postfix
dbname = email
table = mailuser
select_field = maildir
where_field = username
[root@maillinux postfix]# groupadd -g 888 vmail
[root@maillinux postfix]# useradd -u 888 -g 888 vmail
[root@maillinux postfix]# cd /home/vmail/
[root@maillinux vmail]# postconf -e "virtual_mailbox_base = /home/vmail"
[root@maillinux vmail]# postconf -e "virtual_uid_maps = static:888"
[root@maillinux vmail]# postconf -e "virtual_gid_maps = static:888"
[root@maillinux vmail]# postconf -e "virtual_alias_maps = mysql:/etc/postfix/mysql-user.cf"
[root@maillinux vmail]# postconf -e "virtual_mailbox_domains = mysql:/etc/postfix/mysql-domain.cf"
[root@maillinux vmail]# postconf -e "virtual_mailbox_maps = mysql:/etc/postfix/mysql-mailbox.cf"
[root@maillinux vmail]# systemctl restart postfix.service
[root@maillinux vmail]# mail admin@redhat.com
Subject: test
test
.
EOT
[root@maillinux vmail]# mailq
Mail queue is empty
[root@maillinux vmail]# id admin
id: admin: no such user
[root@maillinux vmail]# ls
redhat.com
[root@maillinux vmail]# cd redhat.com
[root@maillinux redhat.com]# ls
admin
[root@maillinux redhat.com]# cd admin
[root@maillinux admin]# ls
cur new tmp
[root@maillinux admin]# cd new
[root@maillinux new]# ls
1489496203.Vfd01I3007d68M337409.maillinux.linux.com
********thunderbird登录收邮件***************
%u - username
%n - user part in user@domain, same as %u if there's no domain
%d - domain part in user@domain, empty if there's no domain
%h - home directory
[root@maillinux new]# vim /etc/dovecot/dovecot.conf
48 login_trusted_networks = 0.0.0.0/0 ##允许访问的网络地址
49 disable_plaintext_auth = no ##明文认证
[root@maillinux new]# vim /etc/dovecot/conf.d/10-auth.conf
123 !include auth-sql.conf.ext ##开启数据库数据认证
[root@maillinux new]# vim /etc/dovecot/dovecot-sql.conf.ext
32 driver = mysql
71 connect = host=localhost dbname=email user=postfix password=postfix
78 default_pass_scheme = PLAIN
107 password_query = \
108 SELECT username, domain, password \
109 FROM mailuser WHERE username = '%u' AND domain = '%d'
125 user_query = SELECT maildir, 888 AS uid, 888 AS gid FROM mailuser WHERE username = '%u'
[root@maillinux new]# vim /etc/dovecot/conf.d/10-mail.conf
30 mail_location = maildir:/home/vmail/%d/%n