基于虚拟帐号的邮件系统extmail(1)

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:

            基于虚拟帐号的邮件系统extmail

       如果你经常使用邮箱的话, 你发现像网易、163等邮箱都是通过使用网页直接申请并且使用的,它提供给用户一种更快捷方便的操作,但我们前面所讲的sendmailpostfix似乎还没有这个功能,并且sendmailpostfix在创建一个用户的时候都是通过在系统上手工创建的,试想一下,如果在一个访问量比较大的邮件服务器,在网络上供人随意的注册用户的话,那么单是管理员创建帐号就会被累死的啊,这还没有考虑效率方面。

        ExtMail是一个以perl语言编写的,面向大容量/isp级应用,并且免费的高性能webmail软件,主要包括ExtMail,Extman两个部分的程序套件。ExtMail套件主要提供从浏览器中登录,使用邮件系统web操作界面。

       ExtMail配置示例

下面我在网上找了一个虚拟的ExtMail的构想图,我们可以借鉴一下

 

从上面的图示中,看到在安装的过程中需要的步骤,我们分解来做这个邮件系统

一.POSTFIX的安装

1>  配置DNS服务器

    在配置时我们使用域名test.com,配置内容自己搞定,自己做测试,区域文件内容如下即可

   

     

2>  在上图中我们可以看出,在Extmail使用中需要httpd php,mysql,openssl dovecot的软件,我们可以先安装。

     [root@localhost named]# yum install httpd  php  php-mysql  mysql  mysql-server  mysql-devel  openssl-devel  dovecot  perl-DBD-MySQL  tcl  tcl-devel  libart_lgpl  libart_lgpl-devel libtool-ltdl  libtool-ltdl-devel  expect      

 3>  在安装postfix之前,我们要先把系统开机启动的sendmail停止,并且设为开机不启动,以免与postfix起冲突

      [root@localhost named]# service sendmail stop

      [root@localhost named]# chkconfig sendmail off

 4> 因为我们这次配置postfix是使用源码安装,我们我们要先安装源码解析工具

     [root@localhost named]# yum groupinstall "Development Libraries" "Development Tools" "X Software Development" "Legacy Software Development"

     可以使用yum grouplist 查看一下,没有安装的在按照此方法安装

5> 安装开发环境之后就可以安装Postfix源码包了

   先为postfix建立一个postfix组与用户,并且安装过程中会让做一些选项,我们按照默认就行了

   [root@localhost postfix-2.9.5]# groupadd -g 2525 postfix

   [root@localhost postfix-2.9.5]# useradd -g postfix -u 2525 -s /sbin/nologin -M postfix

   [root@localhost postfix-2.9.5]# groupadd -g 2526 postdrop

   [root@localhost postfix-2.9.5]# useradd -g postdrop -u 2526 -s /bin/false -M postdrop

   [root@localhost postfix-2.9.5]# 

   [root@localhost ~]# tar -zxvf postfix-2.9.5.tar.gz  -C /usr/local/src/

   [root@localhost postfix-2.9.5]# cd /usr/local/src/postfix-2.9.5/

   在进入目录之后,我们会发现并没有configure文件,我们可以使用另一种方法实现

   [root@localhost postfix-2.9.5]# make makefiles 'CCARGS=-DHAS_MYSQL -I/usr/include/mysql -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl  -DUSE_TLS ' 'AUXLIBS=-L/usr/lib/mysql -lmysqlclient -lz -lm -L/usr/lib/sasl2 -lsasl2   -lssl -lcrypto'

   [root@localhost postfix-2.9.5]# make && make install

   生成别名二进制文件,如果没有这一步,postfix的效率会很低

  [root@localhost postfix-2.9.5]# newaliases

 配置文件,测试发信成功

[root@localhost postfix-2.9.5]# vim /etc/postfix/main.cf   修改如下内容

myhostname = mail.test.com

myorigin = $myhostname

mydomain = test.com

mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain

mynetworks = 192.168.2.0/24, 127.0.0.0/8

 开启postfix服务

 在开启服务的时候,你会发现我们现在还不能使用service的方式启动文件,这是因为在目录/etc/init.d/下还没有postfix的启动文件,我们可以通过两种方法来实现使用service的方法直接实现

   1.直接copy解压目录中的postfix启动文件到/etc/init.d/目录下

     [root@localhost bin]# cd /usr/local/src/postfix-2.9.5/bin

     [root@localhost bin]# cp postfix /etc/init.d/

    但是这两种方法下的postfix服务不能使用restart命令,仅仅可以使用stopstart,还不可以加入开机启动项,所以基本上不用这种方法

  2.这个方法比较麻烦一点,就是把rpm包中的postfix启动脚本文件分离出来copy/etc/init.d目录中

   [root@localhost bin]# cd /mnt/cdrom/Server/ 

[root@localhost Server]# cp postfix-2.3.3-2.1.el5_2.i386.rpm  ~/

[root@localhost Server]# cd

[root@localhost ~]# mkdir postfix

[root@localhost ~]# cd postfix

[root@localhost postfix]# rpm2cpio ../postfix-2.3.3-2.1.el5_2.i386.rpm | cpio -id

16333 blocks

[root@localhost postfix]# cp etc/rc.d/init.d/postfix /etc/init.d/

Postfix加入开机启动行列

 [root@localhost postfix]# chkconfig --add postfix

[root@localhost postfix]# chkconfig postfix on

开启服务

 [root@localhost postfix]# service postfix restart

  Shutting down postfix:                                     [  OK  ]

  Starting postfix:                                          [  OK  ]

6> 配置postfix开启cyrus-sasl的认证功能

   开启saslauthd服务,并且加入开机启动序列。

   [root@localhost named]# service saslauthd start

   Starting saslauthd:                                        [  OK  ]

   [root@localhost named]# chkconfig saslauthd on

查看postfix是否支持sasl认证功能

[root@localhost ~]# /usr/local/src/postfix-2.9.5/bin/postconf -a

   cyrus     //出现这个说明支持sasl认证

   dovecot 

配置postfix主配置文件,开启cyruus-sasl认证功能

[root@localhost ~]# vim /etc/postfix/main.cf      添加如下内容

  ############################CYRUS-SASL############################

  broken_sasl_auth_clients = yes

  smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject_inva

lid_hostname,reject_non_fqdn_hostname,reject_unknown_sender_domain,reject_non_fqdn_s

ender,reject_non_fqdn_recipient,reject_unknown_recipient_domain,reject_unauth_pipeli

ning,reject_unauth_destination

  smtpd_sasl_auth_enable = yes

  smtpd_sasl_local_domain = $myhostname

  smtpd_sasl_security_options = noanonymous

  [root@localhost ~]# vim /usr/lib/sasl2/smtpd.conf    添加如下内容

       pwcheck_method: saslauthd

       mech_list: PLAIN LOGIN

  重启postfix服务

  [root@localhost ~]# service postfix restart

   Shutting down postfix:                                     [  OK  ]

   Starting postfix:                                          [  OK  ]

查看sasl有没有被加载

[root@localhost ~]# telnet 127.0.0.1 25  

    进去之后使用命令  ehlo mail.test.com  

    查看是否有这两行,如果有的话,则配置正确

    250-AUTH PLAIN LOGIN

    250-AUTH=PLAIN LOGIN 

7> mysql配置密码123,并加入开机启动

   [root@localhost ~]# service mysqld start

   [root@localhost ~]# mysqladmin -u root  password "123"

[root@localhost ~]# chkconfig mysqld on

 8> 我们要与mysql进行结合,使用让postfixcourier auth进行结合,安装Courier authentication library

[root@localhost ~]# tar -jxvf courier-authlib-0.63.0.tar.bz2 -C /usr/local/src/

[root@localhost ~]# cd /usr/local/src/courier-authlib-0.63.0/

[root@localhost courier-authlib-0.63.0]# ./configure --prefix=/usr/local/courier-authlib --sysconfdir=/etc --with-authmysql --with-mysql-libs=/usr/lib/mysql --with-mysql-includes=/usr/include/mysql --with-redhat --with-authmysqlrc=/etc/authmysqlrc --with-authdaemonrc=/etc/authdaemonrc --with-ltdl-lib=/usr/lib --with-ltdl-include=/usr/include

[root@localhost courier-authlib-0.63.0]# make && make install

[root@localhost courier-authlib-0.63.0]# chmod 755 /usr/local/courier-authlib/var/spool/authdaemon

[root@localhost courier-authlib-0.63.0]# cp /etc/authdaemonrc.dist /etc/authdaemonrc[root@localhost courier-authlib-0.63.0]# cp /etc/authmysqlrc.dist /etc/authmysqlrc

修改/etc/authdaemonrc文件

[root@localhost ~]# vim /etc/authdaemonrc 修改如下

    authmodulelist="authmysql"

    authmodulelistorig="authmysql"

    daemons=10

修改/etc/authmysqlrc文件

    [root@localhost ~]# vim /etc/authmysqlrc

      修改如下

     MYSQL_SERVER localhost

    MYSQL_PORT 3306                   (指定你的mysql监听的端口,这里使用默认的3306)

     MYSQL_USERNAME  extmail      (这时为后文要用的数据库的所有者的用户名)

     MYSQL_PASSWORD extmail        (密码)

     MYSQL_SOCKET  /var/lib/mysql/mysql.sock

     MYSQL_DATABASE  extmail

     MYSQL_USER_TABLE  mailbox

     MYSQL_CRYPT_PWFIELD  password

     MYSQL_UID_FIELD  '2525'

     MYSQL_GID_FIELD  '2525'

     MYSQL_LOGIN_FIELD  username

     MYSQL_HOME_FIELD  concat('/var/mailbox/',homedir)

     MYSQL_NAME_FIELD  name

     MYSQL_MAILDIR_FIELD  concat('/var/mailbox/',maildir)

   创建启动文件,并加入开机启动行列

     [root@localhost ~]# cp /usr/local/src/courier-authlib-0.63.0/courier-authlib.sysvinit /etc/init.d/courier-authlib

     [root@localhost ~]# chmod 755 /etc/init.d/courier-authlib 

     [root@localhost ~]# chkconfig --add courier-authlib

     [root@localhost ~]# chkconfig courier-authlib on

  把头文件存放在标准路径

       [root@localhost ~]# echo "/usr/local/courier-authlib/lib/courier-authlib" >> /etc/ld.so.conf.d/courier-authlib.conf

       查看一下是否有头文件

       [root@localhost ~]# ldconfig -v   

   开启服务

     [root@localhost ~]# service courier-authlib start

     Starting Courier authentication services: authdaemond

9> 新建虚拟用户邮箱的所在目录,并赋予其权限

   [root@localhost ~]# mkdir -pv /var/mailbox

   [root@localhost ~]# chown -R postfix /var/mailbox

10> 配置SMTP认证

     [root@localhost ~]# vim /usr/lib/sasl2/smtpd.conf    修改如下

      pwcheck_method: authdaemond

      log_level: 3

      mech_list:PLAIN LOGIN

      authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket

 11> 现在让postfix支持虚拟域和虚拟用户

     编辑postfix主文件/etc/postfix/main.cf添加支持虚拟域的代码

     [root@localhost ~]# vim /etc/postfix/main.cf

      ########################Virtual Mailbox Settings########################

      virtual_mailbox_base = /var/mailbox

      virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf

      virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf

       virtual_alias_domains =

       virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf

       virtual_uid_maps = static:2525

       virtual_gid_maps = static:2525

       virtual_transport = virtual

       maildrop_destination_recipient_limit = 1

       maildrop_destination_concurrency_limit = 1

       ##########################QUOTA Settings########################

       message_size_limit = 14336000

       virtual_mailbox_limit = 20971520

       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 Tidy your mailbox and try again later.

       virtual_overquota_bounce = yes

12>  建立数据库

     [root@localhost ~]# tar -zxvf extman-1.1.tar.gz 

     [root@localhost ~]# cd extman-1.1/docs/

     直接使用本目录下的数据库

     [root@localhost docs]# mysql -u root -p < extmail.sql 

     Enter password: 

     [root@localhost docs]# mysql -u root -p < init.sql 

     Enter password: 

     [root@localhost docs]# cp mysql* /etc/postfix/

13> 对用户extmail进行授权

    [root@localhost docs]# mysql -u root -p

    Enter password: 

     Welcome to the MySQL monitor.  Commands end with ; or \g.

     Y our MySQL connection id is 9

     mysql> GRANT all privileges on extmail.* TO extmail@localhost IDENTIFIED BY 'extmail';

     Query OK, 0 rows affected (0.00 sec)

     mysql> GRANT all privileges on extmail.* TO extmail@127.0.0.1 IDENTIFIED BY 'extmail';

    Query OK, 0 rows affected (0.00 sec)

    mysql> FLUSH PRIVILEGES;     //刷新数据库,使配置生效

    Query OK, 0 rows affected (0.00 sec)

   14> 虚拟域现在已经配置好了,但是要想postfix正常工作,我们需要取消中心域

        [root@localhost docs]# vim /etc/postfix/main.cf      //注释掉以下一行

        161  #mydestination = $myhostname, localhost.$mydomain, localhost, 

$mydomain

    重启一下postfix

    [root@localhost docs]# service postfix restart










本文转自 guodong810 51CTO博客,原文链接:http://blog.51cto.com/guodong810/1105352,如需转载请自行联系原作者
相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
网络协议 数据安全/隐私保护 Linux
|
Apache 数据库 数据安全/隐私保护
|
关系型数据库 MySQL 开发工具
|
网络协议 数据安全/隐私保护 开发工具
|
开发工具 安全