- 论坛徽章:
- 7
|
本帖最后由 milujite 于 2010-05-23 18:20 编辑
环境:CentOS 5.4,MySQL,Apache,PHP
主要是觉得用CYRUS-SASL,courier-imap,courier-authlib,maildrop太麻烦了。一大堆组件,邮件系统本来就很杂。能简单则简单,DOVECOT目前已经实现了SASL,而且DOVECOT的SASL能够自动CACHE查询结果,这个是比较棒的。并且DOVECOT可以当LDA使用。而POSTFIX也支持DOVECOT的SASL验证。
先不考虑使用源代码来编译,能用系统包的尽量使用这些包。
1、安装Postfix和Dovecot:
Dovecot直接使用系统yum去安装,而由于默认的Postfix是不支持MySQL查询的,所以需要重新编译Postfix来支持MySQL查询,这里使
用CentOS提供的src包来安装源代码,重新编译打包Postfix。
rpm -Uvh postfix-2.3.x-1.src.rpm
修改/usr/src目录下Postfix的打包文件postfix.spec,修改开头的MySQL字段为:%define MYSQL 1
重新打包Postfix:
rpmbuild -ba postfix.spec
安装完成后使用以下名来来检查Postfix是否支持MySQL查询:
postconf -m | grep mysql
并且使用以下命令来检查是否支持Dovecot的SASL验证:
postconf -a | grep dovecot
2.配置MySQL
cp /usr/share/doc/mysql-server-*/my-large.cnf /etc/my.cnf
设置MySQL默认使用UTF-8编码
[mysqld]
default-character-set = utf8
default-collation = utf8_general_ci
初始化启动数据库:
mysql_install_db --user=mysql
service mysqld start
创建Postfix查询用的数据库:
mysql> CREATE DATABASE postfix;
mysql> CREATE USER postfix@localhost IDENTIFIED BY 'postfix';
mysql> GRANT ALL PRIVILEGES ON postfix.* TO postfix;
mysql> exit
3.配置Dovecot创建虚拟邮箱目录:
mkdir -p /mail
chmod 770 /mail
增加系统用户:
useradd -r -u 101 -g mail -d /mail -s /sbin/nologin -c "Virtual mailbox" vmail
chown vmail.mail /mail
修改/etc/dovecot.conf配置文件:修改Dovecot的SQL连接查询文件/etc/dovecot/sql.conf:- driver = mysql
- default_pass_scheme=MD5 #加上这行,解决Postfixadmin添加的帐号验证不正确
- connect = host=localhost dbname=postfix user=postfix password=postfix
- user_query = SELECT concat('/mail/', maildir) as home, concat('maildir:/mail/', maildir) as mail, 101 AS uid, 12 AS gid, concat('maildir:storage=', quota) AS quota FROM mailbox WHERE username = '%u' AND active = '1'
- password_query = SELECT username as user, password, concat('/mail/', maildir) as userdb_home, concat('maildir:/mail/', maildir) as userdb_mail, 101 as userdb_uid, 12 as userdb_gid FROM mailbox WHERE username = '%u' AND active = '1'
- # fast but now so nice:-)
- #user_query = SELECT '/var/vmail/%d/%n' as home, 'maildir:/mail/%d/%n' as mail, 101 AS uid, 12 AS gid, concat ('dirsize:storage=', quota) AS quota FROM mailbox WHERE username = '%u' AND active = '1'
- # Just in case you are using postfix the delimiter char "+", the above query will probably fail for the username '%
- n' or '%u' and result in a "5.5.1 user unknown" error
- #in this case, you will probalby want to use a separate user and domain part, whilst searching only for the
- destination user part (user_query only):
- # SELECT ... WHERE username = substring_index('%n','+',1) AND userrealm = '%d'
- password_query = SELECT username as user, password, concat('/mail/', maildir) as userdb_home, concat
- ('maildir:/mail/', maildir) as userdb_mail, 101 as userdb_uid, 12 as userdb_gid FROM mailbox WHERE username = '%u' AND active = '1'
- # fast but now so nice:-)
- #password_query = SELECT username as user, password, '/mail/%d/%n' as userdb_home, 'maildir:/mail/%d/%n' as userdb_mail, 101 as userdb_uid, 12 as userdb_gid FROM mailbox WHERE username = '%u' AND active = '1'
复制代码 修改Dovecot的Trash插件配置文件/etc/dovecot/trash.conf: |
评分
-
查看全部评分
|