邮件系统架设postfix+dovecot+mysql+postfixadmi…

2018-07-13 08:53:32来源:编程学习网 阅读 ()

新老客户大回馈,云服务器低至5折

这篇文章介绍一个实现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
注意:本教程并不通用,使用不同的软件版本可能配置方法不一样, 请注意。
安装LAMP
1、第三方库添加
由于postfixadmin要求php-5.2以上的版本,且我们这里使用yum安装lamp,默认的版本是5.1,所以需要添加第三方的rpm库安装php 5.2版本。
rpm --import http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka
vi /etc/yum.repos.d/CentOS-Base.repo
加入:
[utterramblings]
name=Jason's Utter Ramblings Repo
baseurl=http://www.jasonlitka.com/media/EL$releasever/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka
2、开始安装
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-devel
3、启动服务
service httpd start
service mysqld start
mysqladmin -uroot password 'mysql密码'
安装postfix
由于centos自带的postfix不支持mysql,所以只能选择编译安装。
首先删除自带的sendmail
rpm -e sendmail
yum install db4-devel
groupadd -g 1001 postfix
groupadd postdrop
useradd -M -u 1001 -g postfix -s /sbin/nologin postfix
cd /tmp
wget http://postfix.energybeam.com/source/official/postfix-2.8.7.tar.gz
tar xzf postfix-2.8.7.tar.gz
cd postfix-2.8.7
make -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/vmail
virtual_uid_maps = static:1001
virtual_gid_maps = static:1001
1001分别为postfix用户和postfix用户组的id
安装dovecot
yum -y install dovecot
安装postfixadmin
cd /tmp
wget http://softlayer.dl.sourceforge.net/project/postfixadmin/postfixadmin/postfixadmin-2.3.5/postfixadmin-2.3.5.tar.gz
tar xzf postfixadmin-2.3.5.tar.gz -C /var/www/html
mv /var/www/html/postfixadmin-2.3.5 /var/www/html/postfixadmin
cd /var/www/html/postfixadmin
mysql -uroot -p
mysql > 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.cf
virtual_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.cf
virtual_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 support
virtual_create_maildirsize = yes
virtual_mailbox_extended = yes
virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_mailbox_limit_maps.cf
virtual_mailbox_limit_override = yes
virtual_maildir_limit_message = Sorry, the user's maildir has overdrawn his diskspace quota, please try again later.
virtual_overquota_bounce = yes
建立目录sql
mkdir /etc/postfix/sql
以下的几个文件注意修改postfix_password。
vi /etc/postfix/sql/mysql_virtual_alias_maps.cf
内容:
user = postfix
password = postfix_password
hosts = localhost
dbname = postfix
query = SELECT goto FROM alias WHERE address='%s' AND active = '1'
#expansion_limit = 100
vi /etc/postfix/sql/mysql_virtual_alias_domain_maps.cf
内容:
user = postfix
password = postfix_password
hosts = localhost
dbname = postfix
query = 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-domain
user = postfix
password = postfix_password
hosts = localhost
dbname = postfix
query = 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 = postfix
password = postfix_password
hosts = localhost
dbname = postfix
query = 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 = 100
vi /etc/postfix/sql/mysql_virtual_mailbox_maps.cf
内容:
user = postfix
password = postfix_password
hosts = localhost
dbname = postfix
query = SELECT maildir FROM mailbox WHERE username='%s' AND active = '1'
#expansion_limit = 100
vi /etc/postfix/sql/mysql_virtual_alias_domain_mailbox_maps.cf
内容:
user = postfix
password = postfix_password
hosts = localhost
dbname = postfix
query = 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 = postfix
password = postfix_password
hosts = localhost
dbname = postfix
query = 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 plain
userdb sql {
# Path for SQL configuration file, see doc/dovecot-sql-example.conf
args = /etc/dovecot-mysql.conf
}
passdb sql {
# Path for SQL configuration file, see doc/dovecot-sql-example.conf
args = /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 quota
protocol imap {
mail_plugins = quota imap_quota
}

## POP quota
protocol pop3 {
mail_plugins = quota
}

## Local Delivery Agent
protocol lda {
mail_plugins = quota
}

## Dictionary DB proxy
dict {
quota = mysql:/etc/dovecot-dict-quota.conf
}

## Default quota values
plugin {
quota = dict:storage=200000 proxy::quota
}
以下两个文件注意修改postfix_password。
vi /etc/dovecot-mysql.conf
内容:
connect = host=localhost dbname=postfix user=postfix password=postfix_password
driver = mysql

# Default password scheme.
# depends on your $CONF['encrypt'] setting:
# md5crypt -> MD5-CRYPT
# md5 -> PLAIN-MD5
# cleartext -> PLAIN
default_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 = mysql
connect = host=localhost dbname=postfix user=postfix password=postfix_password
default_pass_scheme = MD5-CRYPT
table = quota
select_field = current
where_field = path
username_field = username
启动服务
postmap /etc/aliases
/usr/sbin/postfix start
service dovecot start
roundcube安装
cd /tmp
wget http://voxel.dl.sourceforge.net/project/roundcubemail/roundcubemail/0.7.2/roundcubemail-0.7.2.tar.gz
tar xzf roundcubemail-0.7.2.tar.gz -C /var/www/html
mv /var/www/html/roundcubemail-0.7.2 /var/www/html/webmail
mysql -uroot -p
mysql> CREATE DATABASE roundcubemail;
mysql> GRANT ALL PRIVILEGES ON roundcubemail.* TO [email protected] 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/

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:CentOS 5.0以上不能搭建SSL不能make genkey

下一篇:Linux下为Apache创建专门的用户和用户组

热门词条
热门标签