本文主要介绍了POSTFIX+MYSQL+DOVECOT如何整合在一起,进行邮件的收发
实验环境 linux rhel6.0
首先创建postfix的库,建立一个表 4个元素 userid password domain maibox 插入一个数据项 test@westos.org test westos.org westos.org/test/ service postfix start useradd -u 600 -s /sbin/nologin vmail • postconf -e virtual_mailbox_base=/home/vmail • postconf -e virtual_uid_maps=static:600 • postconf -e virtual_gid_maps=static:600 • postconf -e virtual_alias_maps=mysql:/etc/postfix/mysql-alias.cf • postconf -e virtual_mailbox_domains=mysql:/etc/postfix/mysql-domains.cf • postconf -e virtual_mailbox_maps=mysql:/etc/postfix/mysql-mailboxs.cf
新建三个文件
1 /etc/postfix/mysql-alias.cf
- user = vmail
- password = vmail
- dbname = postfix
- table = users
- select_field = userid
- where_field = userid
2 /etc/postfix/mysql-domains.cf
- user = vmail
- password = vmail
- dbname = postfix
- table = users
- select_field = domain
- where_field = domain
3/etc/postfix/mysql-mailboxs.cf
- user = vmail
- password = vmail
- dbname = postfix
- table = users
- select_field = mailbox
- where_field = userid
* 在mysql中给vmail用户权限
grant all on postfix.* to vmail@localhost identified by 'vmail';
测试
postmap -q “test@westos.org” mysql:/etc/postfix/mysql-alias.cf
postmap -q “westos.org” mysql:/etc/postfix/mysql-domains.cf
postmap -q “test@westos.org” mysql:/etc/postfix/mysql-mailboxs.cf
service postfix restart
mail test@westos.org
之后在/home/vmail/下自己会建立文件夹
至此已可以把邮件收到服务器上的mailbox
之后要用户收到邮件要用dovecot,dovecot是用来收邮件的
配置dovecot
yum install dovecot dovecot-mysql -y
/etc/dovecot/conf.d/10-mail.conf 下改两项
mail_location = maildir:/home/vmail/%d/%n
first_valid_uid = 600
10-auth.conf中的第二个include的注释去掉
cp /usr/share/doc/dovecot-2.0/example.config/dovecot-sql.conf.ext /etc/dovecot
vi /etc/dovecot/dovecot-sql.conf.ext
- driver = mysql
- ...
- connect = host=localhost dbname=postfix user=vmail
- password=vmail
- ...
- default_pass_scheme = PLAIN (明文加密)
- ...
- passwd_query = \
- SELECT userid, domain, password \
- FROM users WHERE userid = '%u'
- ...
- user_query = SELECT mailbox, 600 AS uid,600 AS gid FROM users WHERE userid = '%u'
重启dovecot
测试
telnet localhost 110
user test@westos.org
pass test
list