以下所有操作都是在Red-hat 7.0上
MYSQL和postfix結合,將郵件的用戶,密碼,目錄一些列東西寫到表裏進行身份的驗證!
1.準備實驗環境
2.在數據庫裏建立表,並填充郵件的信息
3.建立MYSQL用戶並授權
4.添加查詢文件
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的查詢條件
vim maildomain.cf #用戶域名查詢
hosts = localhost
user = postuser
password = postuser
dbname = email
table = emailuser
select_field = domain
where_field = domain
vim mailbox.cf #用戶郵箱位置查詢
hosts = localhost
user = postuser
password = postuser
dbname = email
table = emailuser
select_field = maildir
where_field = username
5.測試
[root@westos-mail postfix]# postmap -q "ning@ning.com" mysql:/etc/postfix/mailuser.cf
ning@ning.com
[root@westos-mail postfix]# postmap -q "ning.com" mysql:/etc/postfix/maildomain.cf
ning.com
[root@westos-mail postfix]# postmap -q "ning@ning.com" mysql:/etc/postfix/mailbox.cf
/mnt/ning.com/ning
MYSQL和postfix還有dovecot進行聯合組建郵件系統。現在配置dovecot部分!
1.安裝dovecot及所需要的插件。
yum install dovecot dovecot-mysql -y ##dovecot-mysql是dovecot軟件的插件,可以識別mysql
2.配置dovecot
1.創建接收用戶
groupadd -g 666 vmail
useradd -s /sbin/nologin -u 666 vmail -g 666
2.指定虛擬用戶接收身份,位置和域名
virtual_mailbox_base = /home/vmail ##設定虛擬用戶的郵件目錄
681 virtual_mailbox_maps = mysql:/etc/postfix/mailbox.cf
682 virtual_uid_maps = static:666 ##虛擬用戶建立文件的uid
683 virtual_gid_maps = static:666 ##虛擬用戶建立文件的gid
684 virtual_alias_maps = mysql:/etc/postfix/mailuser.cf
685 virtual_mailbox_domains = mysql:/etc/postfix/maildomain.cf
3.vim /etc/dovecot/dovecot.conf ##主配置文件
24 protocols = imap pop3 lmtp ##支持的協議
48 login_trusted_networks =0.0.0.0/0 ##允許任何網絡段的登入
49 disable_plaintext_auth = no ##使用明文密碼登入
4.vim /etc/dovecot/conf.d/10-auth.conf ##進入認證的配置文件
123 !include auth-sql.conf.ext ##開啓mysql的認證方式
5.cp /usr/share/doc/dovecot-2.2.10/example-config/dovecot-sql.conf.ext /etc/dovecot/dovecot-sql.conf.ext #生成dovecot讀取mysql
6.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’ #從表中找username和domain的信息
125 user_query = SELECT maildir, 666 AS uid, 666 AS gid FROM emailuser WHERE username = ‘%u’ ###uid和gid是666確定接收用戶。
7. vim /etc/dovecot/conf.d/10-mail.conf
30 mail_location = maildir:/home/vmail/%d/%n ##接收郵件的位置
%u - username
18 # %n - user part in user@domain, same as %u if there’s no domain
19 # %d - domain part in user@domain, empty if there’s no domain
17 # %u - username
168 first_valid_uid = 666
175 first_valid_gid = 666
3.配置完成後,重啓服務dovecot
systemctl restart dovecot