CentOS 6安装Sendmail Dovecot Squirrelmail邮件系统

本文记录在本地虚拟机CentOS6上搭建Sendmail + Dovecot + Squirrelmail 的Webmail环境的过程,仅仅是本地局域网的环境测试,不配置DNS, 也没有安全认证,Squirrelmail 版本squirrelmail-webmail-1.4.22。

前言

关于CentOS系统的安装,这里便不做介绍了,大家可以在网上找到很多相关的资料参考。如果已经对下面的命令熟悉的朋友,请直接跳到下一步…

现简单介绍一下一些基本命令的使用:

1、查看系统发行版本

[lz@localhost ~]$ cat /etc/issue
CentOS release 6.9 (Final)
Kernel r on an m

2、查看内核版本

[lz@localhost ~]$ uname -a
Linux localhost.localdomain 2.6.32-71.el6.x86_64 #1 SMP Fri May 20 03:51:51 BST 2011 x86_64 x86_64 x86_64 GNU/Linux

3、获取系统权限

[lz@localhost ~]$ su root      
Password:             【输入lz的密码】
[root@localhost lz]# 

4、让用户能获取root权限

[root@localhost lz]# vim /etc/sudoers

未分类

按esc键,输入:wq! 保存文件,退出,这样lz就用使用sudo命令获取root权限了。来,试试看。

[root@localhost lz]# exit
exit
[lz@localhost ~]$ sudo -i     【获取root权限】
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.
[sudo] password for lz: 
[root@localhost ~]# 

5、修改主机名和hosts文件

[root@mail ~]# cat /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=mail.squirrelmail.com
[root@mail ~]# cat /etc/hosts
127.0.0.1 mail.squirrelmail.com localhost.localdomain
127.0.0.1 squirrelmail.com  localhost.localdomain
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6

重启一下系统,命令提示符前面的就会变成如上所示。

6、更新系统

[root@mail ~]# yum update

这个过程可能需要比较长的时间,耐心等待系统更新完成。

一、Sendmail安装和配置

下面记录Sendmail的安装过程,重要的步骤会给出命令行输出结果。首先,我们需要安装一些依赖包,CentOS系统使用yum来安装,跟Debian/Ubuntu的apt-get 类似可以很方便的安装一些软件。press y

[root@mail mail]# yum install m4 telnet mailx
Loaded plugins: fastestmirror, refresh-packagekit
Setting up Install Process
Loading mirror speeds from cached hostfile
* base: centos.ustc.edu.cn
* extras: centos.ustc.edu.cn
* updates: centos.ustc.edu.cn
Package m4-1.4.13-5.el6.x86_64 already installed and latest version
Package 1:telnet-0.17-48.el6.x86_64 already installed and latest version
Package mailx-12.4-8.el6_6.x86_64 already installed and latest version
Nothing to do

1、Sendmail安装

[root@mail mail]# yum install sendmail sendmail-cf
Loaded plugins: fastestmirror, refresh-packagekit
Setting up Install Process
Loading mirror speeds from cached hostfile
* base: centos.ustc.edu.cn
* extras: centos.ustc.edu.cn
* updates: centos.ustc.edu.cn
Package sendmail-8.14.4-9.el6_8.1.x86_64 already installed and latest version
Package sendmail-cf-8.14.4-9.el6_8.1.noarch already installed and latest version
Nothing to do

我这已经安装好了,仅演示安装过程,在软件的安装过程中,会提示输入[y/N] : y , 当然输入y了

2、Sendmail配置

Sendmail的配置文件默认是在/etc/mail目录下的:

[root@mail mail]# ls /etc/mail
access     aliasesdb-stamp  domaintable.db  local-host-names  mailertable.db  Makefile     sendmail.cf.bak  submit.cf  trusted-users  virtusertable.db
access.db  domaintable      helpfile        mailertable       make            sendmail.cf  sendmail.mc      submit.mc  virtusertable

默认监听的是本地接口地址: 127.0.0.1:25, 我们可以通过命令查看

[root@mail mail]# ps -ef | grep -v grep | grep -i sendmail
root      29409      1  0 14:52 ?        00:00:00 sendmail: accepting connections
smmsp     29419      1  0 14:52 ?        00:00:00 sendmail: Queue runner@01:00:00 for /var/spool/clientmqueue
[root@mail mail]# netstat -an | grep :25 | grep tcp
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN

如果要让Sendmail监听本机的所有接口地址,可以修改sendmail.mc文件, 如果默认监听的是0.0.0.0:25,则可以跳过下面这步。

[root@mail mail]# vim /etc/mail/sendmail.mc
大概在116行, 将如下内容注释掉, 在行首添加dnl
From:
DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl

To:
dnl # DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl

重启一下Sendmail,再查看:

[root@mail ~]# service sendmail restart
Shutting down sm-client:                                   [  OK  ]
Shutting down sendmail:                                    [  OK  ]
Starting sendmail:                                         [  OK  ]
Starting sm-client:                                        [  OK  ]
[root@mail ~]# netstat -an | grep :25 | grep tcp
tcp        0      0 0.0.0.0:25                  0.0.0.0:*                   LISTEN 

下面将使用m4这个工具来创建sendmail.cf这个文件

[root@mail ~]# m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf

在local-host-names增加域名项,表示的是可以用来发送/接收邮件的域名。

[root@mail ~]# cat /etc/mail/local-host-names 
# local-host-names - include all aliases for your machine here.
squirrelmail.com
mail.squirrelmail.com

重启Sendmail,设置开机启动。

[root@mail ~]# service sendmail restart
Shutting down sm-client:                                   [  OK  ]
Shutting down sendmail:                                    [  OK  ]
Starting sendmail:                                         [  OK  ]
Starting sm-client:                                        [  OK  ]
[root@mail ~]# chkconfig sendmail on      【开机启动】

3、Sendmail发送邮件测试: mail命令测试

首先创建两个测试的账户: 使用useradd命令添加两个用户user1和user2、然后用passwd命令更改密码、再将用户添加到mail组。

[root@mail ~]# useradd user1      【添加用户】
[root@mail ~]# useradd user2
[root@mail ~]# passwd user1       【修改密码】
Changing password for user user1.
New password: 
BAD PASSWORD: it does not contain enough DIFFERENT characters
BAD PASSWORD: is too simple
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@mail ~]# passwd user2       【修改密码】
Changing password for user user2.
New password: 
BAD PASSWORD: it does not contain enough DIFFERENT characters
BAD PASSWORD: is too simple
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@mail ~]# gpasswd -a user1 mail    【添加用户到mail组】
Adding user user1 to group mail
[root@mail ~]# gpasswd -a user2 mail
Adding user user2 to group mail

用其中一个账户登陆,给另一个用户发送邮件

[root@mail ~]# su user1      【切换用户user1】      
[user1@mail root]$ mail -s "hello user2" user2      [发送邮件:mail -s "主题内容" "收信人"]
This is a test mail from user1.               【邮件正文】               
.
EOT
[user1@mail root]$ exit
exit
[root@mail ~]# cat /var/mail/user2             【查看邮件】
From [email protected]  Wed Aug  9 17:18:16 2017
Return-Path: <[email protected]>
Received: from mail.squirrelmail.com (mail.squirrelmail.com [127.0.0.1])
    by mail.squirrelmail.com (8.14.4/8.14.4) with ESMTP id v799IFCn003225
    for <[email protected]>; Wed, 9 Aug 2017 17:18:16 +0800
Received: (from user1@localhost)
    by mail.squirrelmail.com (8.14.4/8.14.4/Submit) id v799IFjw003224
    for user2; Wed, 9 Aug 2017 17:18:15 +0800
From: [email protected]
Message-Id: <[email protected]>
Date: Wed, 09 Aug 2017 17:18:15 +0800
To: [email protected]
Subject: hello user2
User-Agent: Heirloom mailx 12.4 7/29/08
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

This is a test mail from user1.

可以看到,上面的邮件发送成功。

[说明] 使用mail命令发送邮件, “-s”后面接邮件主题,然后是接收邮件的账户,直接使用用户名即可,在本域测试。然后输入邮件正文,最后用’.’ ,表示邮件正文结束。

4、Sendmail发送邮件测试: telnet方式测试

未分类

5、防火墙设置

需要设置防火墙允许本机25号端口的数据通过:

[root@starnight mail]# iptables -A INPUT -p tcp -m tcp --dport 25 -j ACCEPT

保存防火墙设置,并重启:

[root@starnight mail]# service iptables save      【保存设置】
iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ]
[root@starnight mail]# service iptables restart    【重启防火墙】
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Unloading modules:                               [  OK  ]
iptables: Applying firewall rules:                         [  OK  ]
[root@starnight mail]# service iptables stop      【关闭,我比较暴力】
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Unloading modules:                               [  OK  ]
[root@starnight mail]#  

到这里,Sendmail的配置就完成了。成功!

二、Dovecot 安装配置

需要先安装一些依赖包:

[root@mail ~]# yum install telnet mailx mutt

1、Dovecot安装

[root@mail ~]# yum install dovecot

2、Dovecot配置

默认情况下,Dovecot的配置文件在/etc/dovecot/下

[root@mail ~]# ls /etc/dovecot/
conf.d  dovecot.conf

修改配置文件/etc/dovecot/dovecot.conf:

[root@mail ~]# vim /etc/dovecot/dovecot.conf

去掉protocols的注释, 即去掉’#’

未分类

打开配置文件/etc/dovecot/conf.d/10-mail.conf:

[root@mail ~]# vim /etc/dovecot/conf.d/10-mail.conf

设置:mail_location = mbox:~/mail:INBOX=/var/mail/%u

未分类

启动和查看Dovecot 服务:

[root@mail ~]# service dovecot start
Starting Dovecot Imap:                                     [  OK  ]
[root@mail ~]# ps -ef | grep -v grep | grep -i dovecot
root       3556      1  0 17:42 ?        00:00:00 /usr/sbin/dovecot
dovecot    3558   3556  0 17:42 ?        00:00:00 dovecot/anvil
root       3559   3556  0 17:42 ?        00:00:00 dovecot/log
root       3561   3556  0 17:42 ?        00:00:00 dovecot/config
[root@mail ~]# netstat -planet | grep -i dove
tcp        0      0 0.0.0.0:993                 0.0.0.0:*                   LISTEN      0          21510      3556/dovecot        
tcp        0      0 0.0.0.0:995                 0.0.0.0:*                   LISTEN      0          21502      3556/dovecot        
tcp        0      0 0.0.0.0:110                 0.0.0.0:*                   LISTEN      0          21500      3556/dovecot        
tcp        0      0 0.0.0.0:143                 0.0.0.0:*                   LISTEN      0          21508      3556/dovecot        
tcp        0      0 :::993                      :::*                        LISTEN      0          21511      3556/dovecot        
tcp        0      0 :::995                      :::*                        LISTEN      0          21503      3556/dovecot        
tcp        0      0 :::110                      :::*                        LISTEN      0          21501      3556/dovecot        
tcp        0      0 :::143                      :::*                        LISTEN      0          21509      3556/dovecot 

3、Dovecot接收邮件测试: mutt

之前在测试Sendmail的时候,用user1这个账户向user2发送了一封邮件,通过查看本地文件进行验证。

[root@mail ~]# mutt -f imap://user2:123456@localhost              【用户user2  密码:123456】

第一次使用在底部会有提示,按照提示进行即可:

未分类
yes

未分类
a

accept 之后,会出现如下邮件列表,

未分类

按回车键即可查看邮件:

未分类

【注】如果新建的用户user1或user2没有加入到mail用户组,通过这种方式查看邮件就会出错。

4、Dovecot接收邮件测试: telnet方式测试

未分类

到这里,Dovecot的配置就完成了。成功!

三、Squirrelmail安装

1、配置Web环境

CentOS Apache2默认应该是安装了的,名称为httpd,如果没有安装可以采用如下命令进行安装

安装:

[root@mail html]# yum install httpd

启动、停止、重启等命令:

[root@mail html]# service httpd start
Starting httpd:                                            [  OK  ]
[root@mail html]# service httpd stop
Stopping httpd:                                            [  OK  ]
[root@mail html]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]

此刻访问虚拟机ip地址,应该就能正常访问了

未分类

2、安装PHP

安装方法也很简单:

[root@mail html]# yum install php

测试: 在web根目录:/var/www/html, 编写如下文件info.php

[root@mail html]# pwd
/var/www/html
[root@mail html]# cat info.php 
<?php
phpinfo();
?>

浏览器访问:http://192.168.1.103/info.php

未分类

3、下载和配置Squirrelmail

下载:

切换到web根目录:使用如下命令下载

[root@mail html]# wget https://nchc.dl.sourceforge.net/project/squirrelmail/stable/1.4.22/squirrelmail-webmail-1.4.22.tar.gz

未分类

解压:

[root@mail html]# tar -zxvf squirrelmail-webmail-1.4.22.tar.gz 
[root@mail html]# ls
info.php  squirrelmail-webmail-1.4.22  squirrelmail-webmail-1.4.22.tar.gz
[root@mail html]# mv squirrelmail-webmail-1.4.22 squirrelmail            【重命名为squirrelmail】
[root@mail html]# ls
info.php  squirrelmail  squirrelmail-webmail-1.4.22.tar.gz
[root@mail html]# cd squirrelmail
[root@mail squirrelmail]# ls
class  config  configure  contrib  data  doc  functions  help  images  include  index.php  locale  plugins  po  README  src  themes
[root@mail squirrelmail]# cd config
[root@mail config]# ls
config_default.php  config_local.php  conf.pl  index.php

配置:

运行配置文件:

[root@mail config]# pwd
/var/www/html/squirrelmail/config
[root@mail config]# ls
config_default.php  config_local.php  conf.pl  index.php
[root@mail config]# ./conf.pl         【运行配置文件】

配置项如下:

未分类

修改一下域名:可以根据自己的需求进行相应的修改。

[2].  Server Settings  => [1].  Domain  => 输入:mail.squirrelmail.com  => 输入:S  [保存数据] =>  输入:R [返回上一级]  => Q [退出]

4、测试和修改

浏览器访问:http://192.168.1.103/squirrelmail/src/configtest.php

未分类

看到上面出现两个错误,我们可以尝试解决一下:

  • PHP short_open_tag = off 需要设置为On

[root@mail html]# vim /etc/php.ini

未分类

  • 在填加两个文件夹data和attach,并赋予写权限
[root@mail ~]# cd /var/local/
[root@mail local]# ls
[root@mail local]# mkdir squirrelmail
[root@mail local]# cd squirrelmail/
[root@mail squirrelmail]# mkdir data
[root@mail squirrelmail]# mkdir attach
[root@mail squirrelmail]# chmod a+w data/
[root@mail squirrelmail]# chmod a+w attach/
[root@mail squirrelmail]# ls -l
total 8
drwxrwxrwx 2 root root 4096 Aug  9 21:39 attach
drwxrwxrwx 2 root root 4096 Aug  9 21:39 data 

重启一下Web服务器: httpd

[root@mail squirrelmail]# service httpd restart

再次访问正常:

未分类

5、登陆Squirrelmail 和邮件发送、接收测试

现在可以访问: http://192.168.1.103/squirrelmail/src/login.php

未分类

用之前新建的账户名: user1/user2 : 123456 登陆, 用user2登陆看看,可以发现已经有一封之前发送的邮件了

未分类

下面我们在Webmail中发送邮件试试:user2 发送给 user1

未分类

再用user1登陆看看, 可以看到我们刚才发送的测试邮件…

未分类

至此,我们在CentOS6 上安装 Sendmail + Dovecot + Squirrelmail 圆满成功。

【注】不得不提的是,这只是个局域网的Webmail的测试环境,如果要实际使用的话,还必须搭建一个DNS服务器,还有跟邮件服务器配套的相关垃圾邮件过滤,认证之类的。

邮件系统架设-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
注意:本教程并不通用,使用不同的软件版本可能配置方法不一样, 请注意。

安装LAMP

1、第三方库添加
由于postfixadmin要求php-5.2以上的版本,且我们这里使用yum安装lamp,默认的版本是5.1,所以需要添加第三方的rpm库安装php 5.2版本。

  1. rpm –import http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka
  2. vi /etc/yum.repos.d/CentOS-Base.repo

加入:

  1. [utterramblings]
  2. name=Jason’s Utter Ramblings Repo
  3. baseurl=http://www.jasonlitka.com/media/EL$releasever/$basearch/
  4. enabled=1
  5. gpgcheck=1
  6. gpgkey=http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka

2、开始安装

  1. 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、启动服务

  1. service httpd start
  2. service mysqld start
  3. mysqladmin -uroot password ‘mysql密码’

安装postfix

由于centos自带的postfix不支持mysql,所以只能选择编译安装。
首先删除自带的sendmail

  1. rpm -e sendmail
  1. yum install db4-devel
  2. groupadd -g 1001 postfix
  3. groupadd postdrop
  4. useradd -M -u 1001 -g postfix  -s /sbin/nologin postfix
  5. cd /tmp
  6. wget http://postfix.energybeam.com/source/official/postfix-2.8.7.tar.gz
  7. tar xzf postfix-2.8.7.tar.gz
  8. cd postfix-2.8.7
  9. make -f Makefile.init makefiles ‘CCARGS=-DHAS_MYSQL -I/usr/include/mysql’   ‘AUXLIBS=-L/usr/lib/mysql -lmysqlclient -lz -lm’
  10. make && make install

简单配置一下postfix:

  1. vi /etc/postfix/main.cf

添加如下代码:

  1. virtual_mailbox_base = /var/mail/vmail
  2. virtual_uid_maps = static:1001
  3. virtual_gid_maps = static:1001

1001分别为postfix用户和postfix用户组的id

安装dovecot

  1. yum -y install dovecot

安装postfixadmin

  1. cd /tmp
  2. wget http://softlayer.dl.sourceforge.net/project/postfixadmin/postfixadmin/postfixadmin-2.3.5/postfixadmin-2.3.5.tar.gz
  3. tar xzf postfixadmin-2.3.5.tar.gz -C /var/www/html
  4. mv /var/www/html/postfixadmin-2.3.5 /var/www/html/postfixadmin
  5. cd /var/www/html/postfixadmin
  6. mysql -uroot -p
  7. mysql > CREATE DATABASE postfix;
  8. mysql > CREATE USER ‘postfix’@’localhost’ IDENTIFIED BY ‘postfix_password’;
  9. mysql > GRANT ALL PRIVILEGES ON `postfix` . * TO ‘postfix’@’localhost’;

postfix_password替换成自己的。
修改配置文件:

  1. vi config.inc.php

找到下面的参数并作修改:

  1. $CONF[‘configured’] = true;
  2. $CONF[‘database_password’] = ‘postfix_password’;
  3. $CONF[‘default_language’] = ‘cn’;
  4. $CONF[‘used_quotas’] = ‘YES’;
  5. $CONF[‘quota’] = ‘YES’;

postfix_password即上一步设置的postfix用户密码。
打开浏览器,输入下面的网址开始安装:
http://your-domain/postfixadmin/setup.php

postfix与postfixadmin整合

  1. vi /etc/postfix/main.cf

按如下添加或修改:

  1. virtual_mailbox_domains = proxy:mysql:/etc/postfix/sql/mysql_virtual_domains_maps.cf
  2. virtual_alias_maps =
  3.    proxy:mysql:/etc/postfix/sql/mysql_virtual_alias_maps.cf,
  4.    proxy:mysql:/etc/postfix/sql/mysql_virtual_alias_domain_maps.cf,
  5.    proxy:mysql:/etc/postfix/sql/mysql_virtual_alias_domain_catchall_maps.cf
  6. virtual_mailbox_maps =
  7.    proxy:mysql:/etc/postfix/sql/mysql_virtual_mailbox_maps.cf,
  8.    proxy:mysql:/etc/postfix/sql/mysql_virtual_alias_domain_mailbox_maps.cf
  9.   
  10. # Additional for quota support
  11. virtual_create_maildirsize = yes
  12. virtual_mailbox_extended = yes
  13. virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_mailbox_limit_maps.cf
  14. virtual_mailbox_limit_override = yes
  15. virtual_maildir_limit_message = Sorry, the user’s maildir has overdrawn his diskspace quota, please try again later.
  16. virtual_overquota_bounce = yes

建立目录sql

  1. mkdir /etc/postfix/sql

以下的几个文件注意修改postfix_password。

  1. vi /etc/postfix/sql/mysql_virtual_alias_maps.cf

内容:

  1. user = postfix
  2. password = postfix_password
  3. hosts = localhost
  4. dbname = postfix
  5. query = SELECT goto FROM alias WHERE address=’%s’ AND active = ‘1’
  6. #expansion_limit = 100
  1. vi /etc/postfix/sql/mysql_virtual_alias_domain_maps.cf

内容:

  1. user = postfix
  2. password = postfix_password
  3. hosts = localhost
  4. dbname = postfix
  5. 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′
  1. vi /etc/postfix/sql/mysql_virtual_alias_domain_catchall_maps.cf

内容:

  1. # handles catch-all settings of target-domain
  2. user = postfix
  3. password = postfix_password
  4. hosts = localhost
  5. dbname = postfix
  6. 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′
  1. vi /etc/postfix/sql/mysql_virtual_domains_maps.cf

内容:

  1. user = postfix
  2. password = postfix_password
  3. hosts = localhost
  4. dbname = postfix
  5. query          = SELECT domain FROM domain WHERE domain=’%s’ AND active = ‘1’
  6. #query          = SELECT domain FROM domain WHERE domain=’%s’
  7. #optional query to use when relaying for backup MX
  8. #query           = SELECT domain FROM domain WHERE domain=’%s’ AND backupmx = ‘0’ AND active = ‘1’
  9. #expansion_limit = 100
  1. vi /etc/postfix/sql/mysql_virtual_mailbox_maps.cf

内容:

  1. user = postfix
  2. password = postfix_password
  3. hosts = localhost
  4. dbname = postfix
  5. query  = SELECT maildir FROM mailbox WHERE username=’%s’ AND active = ‘1’
  6. #expansion_limit = 100
  1. vi /etc/postfix/sql/mysql_virtual_alias_domain_mailbox_maps.cf

内容:

  1. user = postfix
  2. password = postfix_password
  3. hosts = localhost
  4. dbname = postfix
  5. 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′
  1. vi /etc/postfix/sql/mysql_virtual_mailbox_limit_maps.cf

内容:

  1. user = postfix
  2. password = postfix_password
  3. hosts = localhost
  4. dbname = postfix
  5. query = SELECT quota FROM mailbox WHERE username=’%s’ AND active = ‘1’

dovecot与postfixadmin整合

  1. vi /etc/dovecot.conf

按如下修改或添加:

  1. default_mail_env = maildir:/var/mail/vmail/%u/
  2.  
  3. auth default {
  4.   mechanisms plain
  5.   userdb sql {
  6.     # Path for SQL configuration file, see doc/dovecot-sql-example.conf
  7.     args = /etc/dovecot-mysql.conf
  8.   }
  9.   passdb sql {
  10.     # Path for SQL configuration file, see doc/dovecot-sql-example.conf
  11.     args = /etc/dovecot-mysql.conf
  12.   }
  13. }
  14.  
  15. # Valid UID range for users, defaults to 500 and above.
  16. first_valid_uid = 1001  # Change this to your postfix UID
  17.  
  18. ## IMAP quota
  19. protocol imap {
  20.   mail_plugins = quota imap_quota
  21. }
  22.  
  23. ## POP quota
  24. protocol pop3 {
  25.   mail_plugins = quota
  26. }
  27.  
  28. ## Local Delivery Agent
  29. protocol lda {
  30.   mail_plugins = quota
  31. }
  32.  
  33. ## Dictionary DB proxy
  34. dict {
  35.   quota = mysql:/etc/dovecot-dict-quota.conf
  36. }
  37.  
  38. ## Default quota values
  39. plugin {
  40. quota = dict:storage=200000 proxy::quota
  41. }

以下两个文件注意修改postfix_password。

  1. vi /etc/dovecot-mysql.conf

内容:

  1. connect = host=localhost dbname=postfix user=postfix password=postfix_password
  2. driver = mysql
  3.  
  4. # Default password scheme.
  5. # depends on your $CONF[‘encrypt’] setting:
  6. # md5crypt  -> MD5-CRYPT
  7. # md5       -> PLAIN-MD5
  8. # cleartext -> PLAIN
  9. default_pass_scheme = MD5-CRYPT
  10.  
  11. # Query to retrieve password. user can be used to retrieve username in other
  12. # formats also.
  13.  
  14. password_query = SELECT username AS user,password FROM mailbox WHERE username = ‘%u’ AND active=’1′
  15.  
  16. # Query to retrieve user information.
  17.  
  18. 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′
  1. vi /etc/dovecot-dict-quota.conf

内容:

  1. driver = mysql
  2. connect = host=localhost dbname=postfix user=postfix password=postfix_password
  3. default_pass_scheme = MD5-CRYPT
  4. table = quota
  5. select_field = current
  6. where_field = path
  7. username_field = username

启动服务

  1. postmap /etc/aliases
  2. /usr/sbin/postfix start
  3. service dovecot start

roundcube安装

  1. cd /tmp
  2. wget http://voxel.dl.sourceforge.net/project/roundcubemail/roundcubemail/0.7.2/roundcubemail-0.7.2.tar.gz
  3. tar xzf roundcubemail-0.7.2.tar.gz  -C /var/www/html
  4. mv /var/www/html/roundcubemail-0.7.2 /var/www/html/webmail
  5. mysql -uroot -p
  6. mysql> CREATE DATABASE roundcubemail;
  7. mysql> GRANT ALL PRIVILEGES ON roundcubemail.* TO roundcube@localhost IDENTIFIED BY ‘password’;
  8. 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/