邮件系统架设postfix+dovecot+mysql+postfixadmin+roundcube
这篇文章介绍一个实现Web收发的邮件系统方案,利用postfix作为SMTP服务器,实现邮件的发送与接收,使用dovecot作为IMAP服务器,roundcube作为web MUA(邮件用户代理),实现web在线邮件发送与接收。而postfix的虚拟域名和虚拟用户则由postfixadmin管理。系统及软件环境系统:centos-5.8 32位软件:postfix-2.8.7,dovecot-1.0.7,apache-2.2.22,php-5.2.17,mysql-5.1.58,postfixadmin-2.3.5,roundcubemail-0.7.2注意:本教程并不通用,使用不同的软件版本可能配置方法不一样, 请注意。安装LAMP1、第三方库添加由于postfixadmin要求php-5.2以上的版本,且我们这里使用yum安装lamp,默认的版本是5.1,所以需要添加第三方的rpm库安装php 5.2版本。rpm --import http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitkavi /etc/yum.repos.d/CentOS-Base.repo加入:[utterramblings]name=Jason’s Utter Ramblings Repobaseurl=http://www.jasonlitka.com/media/EL$releasever/$basearch/enabled=1gpgcheck=1gpgkey=http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka2、开始安装yum -y install httpd mysql mysql-devel mysql-server php php-pecl-Fileinfo php-mcrypt php-devel php-mysql hp-common php-mbstring php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc pcre pcre-devel3、启动服务service httpd startservice mysqld startmysqladmin -uroot password ’mysql密码’安装postfix由于centos自带的postfix不支持mysql,所以只能选择编译安装。首先删除自带的sendmailrpm -e sendmailyum install db4-develgroupadd -g 1001 postfixgroupadd postdropuseradd -M -u 1001 -g postfix -s /sbin/nologin postfixcd /tmpwget http://postfix.energybeam.com/source/official/postfix-2.8.7.tar.gztar xzf postfix-2.8.7.tar.gzcd postfix-2.8.7make -f Makefile.init makefiles ’CCARGS=-DHAS_MYSQL -I/usr/include/mysql’ ’AUXLIBS=-L/usr/lib/mysql -lmysqlclient -lz -lm’make && make install简单配置一下postfix:vi /etc/postfix/main.cf添加如下代码:virtual_mailbox_base = /var/mail/vmailvirtual_uid_maps = static:1001virtual_gid_maps = static:10011001分别为postfix用户和postfix用户组的id安装dovecotyum -y install dovecot安装postfixadmincd /tmpwget http://softlayer.dl.sourceforge.net/project/postfixadmin/postfixadmin/postfixadmin-2.3.5/postfixadmin-2.3.5.tar.gztar xzf postfixadmin-2.3.5.tar.gz -C /var/www/htmlmv /var/www/html/postfixadmin-2.3.5 /var/www/html/postfixadmincd /var/www/html/postfixadminmysql -uroot -pmysql > CREATE DATABASE postfix;mysql > CREATE USER ’postfix’@’localhost’ IDENTIFIED BY ’postfix_password’;mysql > GRANT ALL PRIVILEGES ON `postfix` . * TO ’postfix’@’localhost’;postfix_password替换成自己的。修改配置文件:vi config.inc.php找到下面的参数并作修改:$CONF[’configured’] = true;$CONF[’database_password’] = ’postfix_password’;$CONF[’default_language’] = ’cn’;$CONF[’used_quotas’] = ’YES’;$CONF[’quota’] = ’YES’;postfix_password即上一步设置的postfix用户密码。打开浏览器,输入下面的网址开始安装:
http://your-domain/postfixadmin/setup.php
postfix与postfixadmin整合vi /etc/postfix/main.cf按如下添加或修改:virtual_mailbox_domains = proxy:mysql:/etc/postfix/sql/mysql_virtual_domains_maps.cfvirtual_alias_maps =proxy:mysql:/etc/postfix/sql/mysql_virtual_alias_maps.cf,proxy:mysql:/etc/postfix/sql/mysql_virtual_alias_domain_maps.cf,proxy:mysql:/etc/postfix/sql/mysql_virtual_alias_domain_catchall_maps.cfvirtual_mailbox_maps =proxy:mysql:/etc/postfix/sql/mysql_virtual_mailbox_maps.cf,proxy:mysql:/etc/postfix/sql/mysql_virtual_alias_domain_mailbox_maps.cf
# Additional for quota supportvirtual_create_maildirsize = yesvirtual_mailbox_extended = yesvirtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_mailbox_limit_maps.cfvirtual_mailbox_limit_override = yesvirtual_maildir_limit_message = Sorry, the user’s maildir has overdrawn his diskspace quota, please try again later.virtual_overquota_bounce = yes建立目录sqlmkdir /etc/postfix/sql以下的几个文件注意修改postfix_password。vi /etc/postfix/sql/mysql_virtual_alias_maps.cf内容:user = postfixpassword = postfix_passwordhosts = localhostdbname = postfixquery = SELECT goto FROM alias WHERE address=’%s’ AND active = ’1’#expansion_limit = 100vi /etc/postfix/sql/mysql_virtual_alias_domain_maps.cf内容:user = postfixpassword = postfix_passwordhosts = localhostdbname = postfixquery = SELECT goto FROM alias,alias_domain WHERE alias_domain.alias_domain = ’%d’ and alias.address = CONCAT(’%u’, ’@’, alias_domain.target_domain) AND alias.active = 1 AND alias_domain.active=’1’vi /etc/postfix/sql/mysql_virtual_alias_domain_catchall_maps.cf内容:# handles catch-all settings of target-domainuser = postfixpassword = postfix_passwordhosts = localhostdbname = postfixquery = SELECT goto FROM alias,alias_domain WHERE alias_domain.alias_domain = ’%d’ and alias.address = CONCAT(’@’, alias_domain.target_domain) AND alias.active = 1 AND alias_domain.active=’1’vi /etc/postfix/sql/mysql_virtual_domains_maps.cf内容:user = postfixpassword = postfix_passwordhosts = localhostdbname = postfixquery = SELECT domain FROM domain WHERE domain=’%s’ AND active = ’1’#query = SELECT domain FROM domain WHERE domain=’%s’#optional query to use when relaying for backup MX#query = SELECT domain FROM domain WHERE domain=’%s’ AND backupmx = ’0’ AND active = ’1’#expansion_limit = 100vi /etc/postfix/sql/mysql_virtual_mailbox_maps.cf内容:user = postfixpassword = postfix_passwordhosts = localhostdbname = postfixquery = SELECT maildir FROM mailbox WHERE username=’%s’ AND active = ’1’#expansion_limit = 100vi /etc/postfix/sql/mysql_virtual_alias_domain_mailbox_maps.cf内容:user = postfixpassword = postfix_passwordhosts = localhostdbname = postfixquery = SELECT maildir FROM mailbox,alias_domain WHERE alias_domain.alias_domain = ’%d’ and mailbox.username = CONCAT(’%u’, ’@’, alias_domain.target_domain) AND mailbox.active = 1 AND alias_domain.active=’1’vi /etc/postfix/sql/mysql_virtual_mailbox_limit_maps.cf内容:user = postfixpassword = postfix_passwordhosts = localhostdbname = postfixquery = SELECT quota FROM mailbox WHERE username=’%s’ AND active = ’1’dovecot与postfixadmin整合vi /etc/dovecot.conf按如下修改或添加:default_mail_env = maildir:/var/mail/vmail/%u/
auth default {mechanisms plainuserdb sql {# Path for SQL configuration file, see doc/dovecot-sql-example.confargs = /etc/dovecot-mysql.conf}passdb sql {# Path for SQL configuration file, see doc/dovecot-sql-example.confargs = /etc/dovecot-mysql.conf}}
# Valid UID range for users, defaults to 500 and above.first_valid_uid = 1001 # Change this to your postfix UID
## IMAP quotaprotocol imap {mail_plugins = quota imap_quota}
## POP quotaprotocol pop3 {mail_plugins = quota}
## Local Delivery Agentprotocol lda {mail_plugins = quota}
## Dictionary DB proxydict {quota = mysql:/etc/dovecot-dict-quota.conf}
## Default quota valuesplugin {quota = dict:storage=200000 proxy::quota}以下两个文件注意修改postfix_password。vi /etc/dovecot-mysql.conf内容:connect = host=localhost dbname=postfix user=postfix password=postfix_passworddriver = mysql
# Default password scheme.# depends on your $CONF[’encrypt’] setting:# md5crypt -> MD5-CRYPT# md5 -> PLAIN-MD5# cleartext -> PLAINdefault_pass_scheme = MD5-CRYPT
# Query to retrieve password. user can be used to retrieve username in other# formats also.
password_query = SELECT username AS user,password FROM mailbox WHERE username = ’%u’ AND active=’1’
# Query to retrieve user information.
user_query = SELECT maildir, 1001 AS uid, 1001 AS gid, CONCAT(’dict:storage=’,floor(quota/1000),’ proxy::quota’) as quota FROM mailbox WHERE username = ’%u’ AND active=’1’vi /etc/dovecot-dict-quota.conf内容:driver = mysqlconnect = host=localhost dbname=postfix user=postfix password=postfix_passworddefault_pass_scheme = MD5-CRYPTtable = quotaselect_field = currentwhere_field = pathusername_field = username启动服务postmap /etc/aliases/usr/sbin/postfix startservice dovecot startroundcube安装cd /tmpwget http://voxel.dl.sourceforge.net/project/roundcubemail/roundcubemail/0.7.2/roundcubemail-0.7.2.tar.gztar xzf roundcubemail-0.7.2.tar.gz -C /var/www/htmlmv /var/www/html/roundcubemail-0.7.2 /var/www/html/webmailmysql -uroot -pmysql> CREATE DATABASE roundcubemail;mysql> GRANT ALL PRIVILEGES ON roundcubemail.* TO roundcube@localhost IDENTIFIED BY ’password’;mysql> FLUSH PRIVILEGES;现在你可以浏览器打开以下网址安装:
http://yourdomain/webmail/installer/
详细的roundcubemail安装说明可以参考:http://blog.dvxj.com/pandola/roundcube-install-config.html这样就实现了完整的邮件系统功能,没有实现的是smtp的认证,即无法使用像outlook express客户端发送邮件,如有需要,可以搜索sasl方面的教程配置。相关网站:
http://www.postfix.org/
http://www.dovecot.org/
http://postfixadmin.sourceforge.net/
http://roundcube.net/
相关文章: