SMTP:simple mail tansfer protocol

    本身能实现路由功能,比如从一个用户到另一个用户

ESMTP:Extended

POP3:Post Office Protocol

IMAP4:Internet Mail Access Protocol


SMTP(25/tcp)


邮件传输:MT

邮件投递:MD

邮件用户:MU

邮件用户代理:MUA mail user agent

邮件传输代理:MTA mail tansfer agent

邮件投递代理:MDA mail delivery agent

邮件取回代理:MRA mail retrieval Agent

MUA--->MTA :使用SMTP协议


SMTPD邮件传输分为两类:

    LMTP:本地邮件传输协议

    调用本地smtp客户端再到发送到邮件到对方的SMTPD


Open relay:开放中继


SASL:simple Authintication secure layer,简单认证安全层


LDAP:Lightweight Directory Access Protocol


虚拟用户:仅用户访问某服务的数字标识


MTA:邮件传输代理软件:

    sendmail:配置文件语法(M4编写),结合SUID

    qmail:发送速度相当快, 2个数量级于sendmail

    postfix:模块化设计,不使用SUID,安全,跟sendmail兼容,效率高,比sendmail高差不多4倍

    exim:配置语法简单,剑桥大学开源项目

    exchange:有异步消息协作平台

SASL:SMTPD的用户认证功能实现

    syrus-sasl V2版本

    courier--authlib:一般用来做sasl的认证机制,功能更强大,和灵活

MDA:邮件投递的实现

    procmail(sendmail中使用)

    maildrop

MRA:pop3,ima协议的实现

    cyrus-imap

    dovecot:语法简单,功能强大

MUA:邮件客户端

    outlook,foxmail,Thunderbird,Evolution,mutt(专业级文件界面)

WEBMAIL: web界面邮件实现

    squirrelmail

    openwebmail

    Extmail(extman)

        EMOS,Centos定制版本

smtps

pop3s

imaps


实验实现:

  发邮件方:  Postfix + SASL(Courier-authlib) + mysql

  收邮件方:Dovecot + MySQL

  WebMail: Extmail + extman + httpd


安装配置postfix:

# groupadd -g 2525 postfix
# useradd -g postfix -u 2525 -s /sbin/nologin -M postfix
# groupadd -g 2526 postdrop
# useradd -g postdrop -u 2526 -s /sbin/nologin -M postdrop

# tar zxvf postfix-2.9.3.tar.gz
# cd postfix-2.9.3
# 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'
# make
# make install
CCARGS:指定C编译参数,告诉系统在哪个位置查找头文件 
-DHAS_MYSQL:MYSQL的连接功能
-I/usr/include/mysql:头文件路径
-DUSE_SASL_AUTH:启用SASL认证
-I/usr/include/sasl:SASL头文件路径
-DUSE_TLS:使用支持TLS加密
AUXLIBS:辅助的库文件路径
-lz:压缩文件
-lm:模块文件
-lsasl2:使用SASL2库
-lssl:SSL的库文件
-lcrypto:加密的库文件


#编译安装的SQL,头文件和库文件路径有区别,如下
# make makefiles 'CCARGS=-DHAS_MYSQL -I/usr/local/mysql/include -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl  -DUSE_TLS ' 'AUXLIBS=-L/usr/local/mysql/lib -lmysqlclient -lz -lm -L/usr/lib/sasl2 -lsasl2  -lssl -lcrypto'


按照以下的提示输入相关的路径([]号中的是缺省值,”]”后的是输入值,省略的表示采用默认值)

  install_root: [/] /
  tempdir: [/root/postfix-2.9.3] /tmp/postfix   #临时目录
  config_directory: [/etc/postfix] /etc/postfix  #配置目录
  daemon_directory: [/usr/libexec/postfix]     #服务进程
  command_directory: [/usr/sbin]     #命令目录
  queue_directory: [/var/spool/postfix]    #邮件队列位置
  sendmail_path: [/usr/sbin/sendmail]    #smtp客户端
  newaliases_path: [/usr/bin/newaliases]    #生成新别名
  mailq_path: [/usr/bin/mailq]    #邮件队列工具
  mail_owner: [postfix]    #服务运行者
  setgid_group: [postdrop]   #实现域内用户邮箱投递
    html_directory: [no]/var/www/html/postfix     #帮助文档
    manpages: [/usr/local/man]    #MAN手册
    readme_directory: [no]    #其他帮助文档

POST配置文件:

    post核心模块

        master:/etc/postfix/master.cf

    整个邮件的配置

        /etc/postfix/main.cf

        参数 = 值 :参数必须写在行的绝对行首,以空白开关的行被认为是上一行的延续


Postconf命令:实现配置postfix的命令行工具

    -d:查看默认配置信息

    -n: 查看修改的配置信息

    -m: 查看postfix默认支持的用户认证方式,即查找表类型

    -A: 查看支持的SASL客户端的插件类型

    -e: PARMATER=VALUE:更改某参数配置信息,并保存至main.cf文件中

    -a: 服务器商支持的sasl插件类型


smtp--->smtpd的工作步骤:

    1、hello(确认服务器状态,服务器并给予回复)

    2、mail from(确认发件人)

    3、rcpt to(rcpt命令确认收件人)

    4、data(邮件正文,以.为结尾,表示邮件内容填写完成,服务器接收并发送)

smtp协议命令:

    helo(smtp协议)

    ehlo(Esmtp协议)

    mail from:mail@address.com

    rcpt to:

    data


邮件的状态码:

    1XX:纯信息

    2XX:正确类信息

    3XX:上一步操作尚未完成 ,需要继续补充

    4XX:暂时性错误

    5XX:永久性错误


alias:邮件别名

    abc@mageedua.com:postmaster@mageedua.com

    /etc/aliases,aliases配置文件

    /etc/aliases --> hash --> /etc/aliases.db

    使用newaliases可以创建/etc/aliases.db


postfix默认把本机的IP地址所在的网段识别为本地网络,并且给予中断



postfix服务启动脚本:

#!/bin/bash
#
# postfix      Postfix Mail Transfer Agent
#
# chkconfig: 2345 80 30
# description: Postfix is a Mail Transport Agent, which is the program \
#              that moves mail from one machine to another.
# processname: master
# pidfile: /var/spool/postfix/pid/master.pid
# config: /etc/postfix/main.cf
# config: /etc/postfix/master.cf

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ $NETWORKING = "no" ] && exit 3

[ -x /usr/sbin/postfix ] || exit 4
[ -d /etc/postfix ] || exit 5
[ -d /var/spool/postfix ] || exit 6

RETVAL=0
prog="postfix"

start() {
	# Start daemons.
	echo -n $"Starting postfix: "
        /usr/bin/newaliases >/dev/null 2>&1
	/usr/sbin/postfix start 2>/dev/null 1>&2 && success || failure $"$prog start"
	RETVAL=$?
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/postfix
        echo
	return $RETVAL
}

stop() {
  # Stop daemons.
	echo -n $"Shutting down postfix: "
	/usr/sbin/postfix stop 2>/dev/null 1>&2 && success || failure $"$prog stop"
	RETVAL=$?
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/postfix
	echo
	return $RETVAL
}

reload() {
	echo -n $"Reloading postfix: "
	/usr/sbin/postfix reload 2>/dev/null 1>&2 && success || failure $"$prog reload"
	RETVAL=$?
	echo
	return $RETVAL
}

abort() {
	/usr/sbin/postfix abort 2>/dev/null 1>&2 && success || failure $"$prog abort"
	return $?
}

flush() {
	/usr/sbin/postfix flush 2>/dev/null 1>&2 && success || failure $"$prog flush"
	return $?
}

check() {
	/usr/sbin/postfix check 2>/dev/null 1>&2 && success || failure $"$prog check"
	return $?
}

restart() {
	stop
	start
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart)
	stop
	start
	;;
  reload)
	reload
	;;
  abort)
	abort
	;;
  flush)
	flush
	;;
  check)
	check
	;;
  status)
  	status master
	;;
  condrestart)
	[ -f /var/lock/subsys/postfix ] && restart || :
	;;
  *)
	echo $"Usage: $0 {start|stop|restart|reload|abort|flush|check|status|condrestart}"
	exit 1
esac

exit $?

# END

添加服务

[root@localhost postfix-3.0.1]# chmod +x /etc/init.d/postfix
[root@localhost postfix-3.0.1]# chkconfig --add postfix
[root@localhost postfix-3.0.1]# chkconfig --list postfix
postfix        	0:off	1:off	2:on	3:on	4:on	5:on	6:off
[root@localhost postfix-3.0.1]# service postfix restart
Shutting down postfix:                                     [  OK  ]
Starting postfix:                                          [  OK  ]


/etc/postfix/main.cf

进行一些基本配置,测试启动postfix并进行发信

# vim /etc/postfix/main.cf

修改以下几项为您需要的配置

myhostname = mail.magedu.com

myorigin = magedu.com

mydomain = magedu.com

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

mynetworks = 192.168.1.0/24, 127.0.0.0/8

inet_interfaces = 

说明:

myorigin参数用来指明发件人所在的域名,即做发件地址伪装;

mydestination参数指定postfix接收邮件时收件人的域名,即您的postfix系统要接收到哪个域名的邮件;

myhostname 参数指定运行postfix邮件系统的主机的主机名,默认情况下,其值被设定为本地机器名;

mydomain 参数指定您的域名,默认情况下,postfix将myhostname的第一部分删除而作为mydomain的值;

mynetworks 参数指定你所在的网络的网络地址,postfix系统根据其值来区别用户是远程的还是本地的,如果是本地网络用户则允许其访问;

inet_interfaces 参数指定postfix系统监听的网络接口;


注意:

1、在postfix的配置文件中,参数行和注释行是不能处在同一行中的;

2、任何一个参数的值都不需要加引号,否则,引号将会被当作参数值的一部分来使用;

3、每修改参数及其值后执行 postfix reload 即可令其生效;但若修改了inet_interfaces,则需重新启动postfix;

4、如果一个参数的值有多个,可以将它们放在不同的行中,只需要在其后的每个行前多置一个空格即可;postfix会把第一个字符为空格或tab的文本行视为上一行的延续;



配置postfix服务步骤:

    1、设置主机名

[root@localhost postfix-3.0.1]# hostname btsbox.com
[root@localhost postfix-3.0.1]# vim /etc/sysconfig/network
[root@localhost postfix-3.0.1]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=btsbox.com

    2、建立DNS服务器

    3、建立MRA

       安装dovecot软件

    4、验证用户身份发邮件,结合sasl认证

    yum install dovecot


dovecot有SASL认证能力,支持pop3,imap4,pops,imaps


邮箱格式:mbox:一个文件存储所有邮件,中间有分隔符

          maildir:一个文件存储一款邮件 ,所有邮件存储在一个目录中


dovecot配置文件

    /etc/dovecot.conf

        启用protocols= imap pop3

    service dovecot start 启动服务


命令行收邮件命令:

    telnet 10.189.8.109 110

    USER username  #指定用户名

    PASS password    #指定密码

    LIST    #查看邮件列表

    RETR 1    #查看第一封邮件 


postfix+sasl用户认证

1、启动sasl,启动sasl服务

    /etc/rc.d/init.d/saslauthd 服务脚本

    /etc/sysconfig/saslauthd 配置文件

    saslauthd -v :查看支持哪些认证机制,默认为pam

    testsaslauthd :测试saslauthd    

        testsaslauthd -u openstack -p openstack 

2、让postfix与sasl结合

    编辑/etc/postfix/main.cf文件

添加以下内容:
############################CYRUS-SASL############################
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject_invalid_hostname,reject_non_fqdn_hostname,reject_unknown_sender_domain,reject_non_fqdn_sender,reject_non_fqdn_recipient,reject_unknown_recipient_domain,reject_unauth_pipelining,reject_unauth_destination
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $myhostname
smtpd_sasl_security_options = noanonymous
smtpd_sasl_application_name = smtpd
smtpd_banner = Welcome to our $myhostname ESMTP,Warning: Version not Available!

   编辑/usr/lib/sasl2/smtpd.conf

添加如下内容:
pwcheck_method: saslauthd
mech_list: PLAIN LOGIN

    让postfix重新加载配置文件

    #/usr/sbin/postfix reload




实现postfix基于客户端的访问控制


1、基于客户端的访问控制概览


postfix内置了多种反垃圾邮件的机制,其中就包括“客户端”发送邮件限制。客户端判别机制可以设定一系列客户信息的判别条件:

smtpd_client_restrictions

smtpd_data_restrictions

smtpd_helo_restrictions

smtpd_recipient_restrictions

smtpd_sender_restrictions


上面的每一项参数分别用于检查SMTP会话过程中的特定阶段,即客户端提供相应信息的阶段,如当客户端发起连接请求时,postfix就可以根据配置文件中定义的smtpd_client_restrictions参数来判别此客户端IP的访问权限。相应地,smtpd_helo_restrictions则用于根据用户的helo信息判别客户端的访问能力等等。


如果DATA命令之前的所有内容都被接受,客户端接着就可以开始传送邮件内容了。邮件内容通常由两部分组成,前半部分是标题(header),其可以由header_check过滤,后半部分是邮件正文(body),其可以由check_body过滤。这两项实现的是邮件“内容检查”。


postfix的默认配置如下:

smtpd_client_restrictions =

smtpd_data_restrictions =

smtpd_end_of_data_restrictions =

smtpd_etrn_restrictions =

smtpd_helo_restrictions =

smtpd_recipient_restrictions = permit_mynetworks, reject_unauth_destination

smtpd_sender_restrictions =


这限制了只有mynetworks参数中定义的本地网络中的客户端才能通过postfix转发邮件,其它客户端则不被允许,从而关闭了开放式中继(open relay)的功能。


Postfix有多个内置的限制条件,如上面的permit_mynetworks和reject_unauth_destination,但管理员也可以使用访问表(access map)来自定义限制条件。自定义访问表的条件通常使用check_client_access, check_helo_access, check_sender_access, check_recipient_access进行,它们后面通常跟上type:mapname格式的访问表类型和名称。其中,check_sender_access和check_recipient_access用来检查客户端提供的邮件地址,因此,其访问表中可以使用完整的邮件地址,如admin@magedu.com;也可以只使用域名,如magedu.com;还可以只有用户名的部分,如marion@。


    connection:smtpd_client_restrictions =  (限定哪此用户可以连接指令)

    helo:smtpd_hello_restrictions = user1 (限定哪此用户可以使用hello指令)

    mail from:smtpd_sender_restrictions =

    rcpt to: smtpd_recipient_restrictions = (以上步骤真正实现拒绝用户,是此步骤)

    data:smtpd_data_restrictions =

    

mail from:user1@ (表示来自此用户的所有域都拒绝

          a.com(表示所有a.com所有的域都不让发邮件)

smtpd_recipient_restrictions = permit_mynetworks,reject_unauth_destination

    permit_mynetworks:表示只允许mynetworks指定的主机中继

    reject_unauth_destination:表示拒绝所有未经认证的用户


实现示例1


这里以禁止172.16.100.200这台主机通过工作在172.16.100.1上的postfix服务发送邮件为例演示说明其实现过程。访问表使用hash的格式。


(1)首先,编辑/etc/postfix/access文件,以之做为客户端检查的控制文件,在里面定义如下一行:

172.16.100.200REJECT


(2)将此文件转换为hash格式

# postmap /etc/postfix/access


(3)配置postfix使用此文件对客户端进行检查

编辑/etc/postfix/main.cf文件,添加如下参数:

smtpd_client_restrictions = check_client_access hash:/etc/postfix/access
smtpd_hello_restrictions = check_hello_access mysql:/etc/postfix/mysql_user (数据库格式)
smtpd_recipient_restrictions = check_recipient_access hash:/etc/postfix/recipient,permit_mynetworks, reject_unauth_destination #后面两项必须不能少,前面一项必须写前面,次序要匹配


(4)让postfix重新载入配置文件即可进行发信控制的效果测试了。


实现示例2


这里以禁止通过本服务器向microsoft.com域发送邮件为例演示其实现过程。访问表使用hash的格式。

(1)首先,建立/etc/postfix/denydstdomains文件(文件名任取),在里面定义如下一行:

microsoft.comREJECT


(2)将此文件转换为hash格式

# postmap /etc/postfix/denydstdomains


(3)配置postfix使用此文件对客户端进行检查

编辑/etc/postfix/main.cf文件,添加如下参数:

smtpd_recipient_restrictions = check_recipient_access hash:/etc/postfix/denydstdomains, permit_mynetworks, reject_unauth_destination


(4)让postfix重新载入配置文件即可进行发信控制的效果测试了。


4、检查表格式的说明


hash类的检查表都使用类似如下的格式:

pattern   action


检查表文件中,空白行、仅包含空白字符的行和以#开头的行都会被忽略。以空白字符开头后跟其它非空白字符的行会被认为是前一行的延续,是一行的组成部分。


(1)关于pattern

其pattern通常有两类地址:邮件地址和主机名称/地址。


邮件地址的pattern格式如下:

user@doain  用于匹配指定邮件地址m;

domain.tld   用于匹配以此域名作为邮件地址中的域名部分的所有邮件地址;

user@ 用于匹配以此作为邮件地址中的用户名部分的所有邮件地址;


主机名称/地址的pattern格式如下:

domain.tld   用于匹配指定域及其子域内的所有主机;

.domain.tld   用于匹配指定域的子域内的所有主机;

net.work.addr.ess

net.work.addr

net.work

net        用于匹配特定的IP地址或网络内的所有主机;

network/mask  CIDR格式,匹配指定网络内的所有主机;


(2)关于action


接受类的动作:

OK   接受其pattern匹配的邮件地址或主机名称/地址;

全部由数字组成的action   隐式表示OK;


拒绝类的动作(部分):

4NN text 

5NN text 

    其中4NN类表示过一会儿重试;5NN类表示严重错误,将停止重试邮件发送;421和521对于postfix来说有特殊意义,尽量不要自定义这两个代码;

REJECT optional text...   拒绝;text为可选信息;

DEFER optional text...    拒绝;text为可选信息; 



为postfix开启基于cyrus-sasl的认证功能


使用以下命令验正postfix是否支持cyrus风格的sasl认证,如果您的输出为以下结果,则是支持的:

# /usr/local/postfix/sbin/postconf  -a

cyrus

dovecot


#vim /etc/postfix/main.cf

添加以下内容:

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

broken_sasl_auth_clients = yes  #开启通过sasl验证用户来发邮件,客户端限制

smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject_invalid_hostname,reject_non_fqdn_hostname,reject_unknown_sender_domain,reject_non_fqdn_sender,reject_non_fqdn_recipient,reject_unknown_recipient_domain,reject_unauth_pipelining,reject_unauth_destination

reject_invalid_hostname  #拒绝主机不合法的来收发邮件
reject_non_fqdn_hostname #主机名不是FQDN格式,也不允许
reject_unknown_sender_domain  #拒绝无法识别的发件人
reject_non_fqdn_sender #拒绝没有fqdn的发件人
reject_non_fqdn_recipient  #拒绝没有fqdn的接收人
reject_unknown_recipient_domain #拒绝无法识别的收件域
reject_unauth_pipelining #无法认证的管道
reject_unauth_destination # 拒绝无法认证的用户

smtpd_sasl_auth_enable = yes #启用smtpd+sasl认证功能

smtpd_sasl_local_domain = $myhostname #本地主机的认证

smtpd_sasl_security_options = noanonymous #sasl的安全选项,不支持匿名用户

smtpd_sasl_application_name = smtpd #哪个程序要使用sasl功能,2.3版本以前使用这行

smtpd_sasl_path = smtpd #哪个程序要使用sasl功能,2.4及以后版本需要使用这行代码

smtpd_banner = Welcome to our $myhostname ESMTP,Warning: Version not Available! #欢迎信息


# vim /usr/lib/sasl2/smtpd.conf

添加如下内容:

log_level 3  #定义日志级别,可以看用户验证级别的日志,在邮件的日志中

pwcheck_method: saslauthd

mech_list: PLAIN LOGIN  #PLAIN LOGIN是两种认证机制


#关闭/etc/postfix/main.cf中的mynetworks选项,如下

 mynetworks = 127.0.0.0/8  #只给本机中继,其他的都使用sasl功能认证


让postfix重新加载配置文件

#/usr/sbin/postfix reload


重启saslauthd服务

#server saslauthd restart 


# telnet localhost 25

Trying 127.0.0.1...

Connected to localhost.localdomain (127.0.0.1).

Escape character is '^]'.

220 Welcome to our mail.magedu.com ESMTP,Warning: Version not Available!

ehlo mail.magedu.com

250-mail.magedu.com

250-PIPELINING

250-SIZE 10240000

250-VRFY

250-ETRN

250-AUTH PLAIN LOGIN

250-AUTH=PLAIN LOGIN               (请确保您的输出以类似两行)

250-ENHANCEDSTATUSCODES

250-8BITMIME

250 DSN



Mutt命令的使用:

mut -f pop://root@mail.btsbox.com  #-f指定协议 root用户 @指定主机



Postfix虚拟域的实现:

    1、smtp借助sasl函数库调用courier-authlib程序到mysql的用户认证;

    2、pop、imap借助dovecot程序实现到mysql的用户认证

    3、webmail使用extmail,extman程序实现,exmail本身也可以实现用户到mysql的认证和用户的           邮件收发

    4、exmail,extman需依赖httpd服务,由于exmail是perl开发语言,需要http对perl模块的支持

SMTP使用courier-authlib完成认证:


安装postfix-3.0.1

make makefiles 'CCARGS=-DHAS_MYSQL -I/usr/include/mysql -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl  -DUSE_TLS ' 'AUXLIBS=-L/usr/lib64/mysql -lmysqlclient -lz -lm -L/usr/lib64/sasl2 -lsasl2  -lssl -lcrypto'
make
make install 

#提供服务脚本配置文件
vim /etc/init.d/postfix
chmod +x /etc/init.d/postfix
chkconfig --add postfix
#vim /etc/postfix/main.cf
#配置main.cf中的选项
mynetworks = 127.0.0.0/8
inet_interfaces = all
并添加以下内容:
############################CYRUS-SASL############################
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject_invalid_hostname,reject_non_fqdn_hostname,reject_unknown_sender_domain,reject_non_fqdn_sender,reject_non_fqdn_recipient,reject_unknown_recipient_domain,reject_unauth_pipelining,reject_unauth_destination
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $myhostname
smtpd_sasl_security_options = noanonymous
smtpd_sasl_path = smtpd
smtpd_banner = Welcome to our $myhostname ESMTP,Warning: Version not Available!

安装courier-authlib

#需要先安装courier-unicode-1.3
tar xf courier-unicode-1.3.tar.bz2 
cd courier-unicode-1.3
./configure 
make && make install

#编译安装courier-authlib

  102  ./configure \
      --prefix=/usr/local/courier-authlib \ #指定安装路径
      --sysconfdir=/etc \    #指定配置文件存放路径
      --without-authpam \    #关闭pam认证
      --without-authshadow \    #关闭shadow认证
      --without-authvchkpw \    #关闭vcchkpw认证
      --without-authpgsql \    #关闭pgsql认证
      --with-authmysql \    #开启mysql认证
      --with-mysql-libs=/usr/lib64/mysql \    #指定mysql的库文件
      --with-mysql-includes=/usr/include/mysql \    #指定mysql的头文件
      --with-redhat \    #指定安装平台,可以优化环境
      --with-authmysqlrc=/etc/authmysqlrc \  #基于mysql认证的配置文件
      --with-authdaemonrc=/etc/authdaemonrc \ #authlib本身的配置文件
      --with-mailuser=postfix \ #服务运行用户
      --with-mailgroup=postfix     #服务运行组
备注:可以使用--with-authdaemonvar=/var/spool/authdaemon选项来指定进程套按字目录路径

#提供sysv服务脚本:
[root@mail courier-authlib-0.66.3]# cp courier-authlib.sysvinit /etc/init.d/courier-authlib
[root@mail courier-authlib-0.66.3]# chmod 755 /etc/init.d/courier-authlib 
[root@mail courier-authlib-0.66.3]# chkconfig --add courier-authlib 
[root@mail courier-authlib-0.66.3]# chkconfig --list courier-authlib
courier-authlib	0:off	1:off	2:on	3:on	4:on	5:on	6:of

#配置courier-authlib服务
[root@mail courier-authlib-0.66.3]# chmod 755 /usr/local/courier-authlib/var/spool/authdaemon/   #由于courier-authlib与postfix安装在一台电脑,需使用socket通信,需确保其他用户可访问。
#重命名authlib的配置文件和mysql的连接配置文件
[root@mail courier-authlib-0.66.3]# cp /etc/authdaemonrc.dist /etc/authdaemonrc
[root@mail courier-authlib-0.66.3]# cp /etc/authmysqlrc.dist /etc/authmysqlrc

#修改/etc/authdaemonrc配置文件
authmodulelist="authmysql"    #支持的认证模块只保留authmsyql
authmodulelistorig="authmysql" #支持的原始模块也只保留authmysql
daemons=10    #默认启动的进程
authdaemonvar=/usr/local/courier-authlib/var/spool/authdaemon  #courier-authlib的socket保存路径,默认不更改
DEBUG_LOGIN=0  #调试日志,级别有0 1 2 ,0表示关闭,1表示开启 2表示开启同时记录密码

#修改/etc/authmysqlrc配置文件
MYSQL_SERVER            localhsot  #连接的mysql服务器位置
MYSQL_USERNAME          extmail    #extmail是extmail连接数据库extmail所使用的extmail用户
MYSQL_PASSWORD          extmail    #密码与上一致
MYSQL_SOCKET  /var/lib/mysql/mysql.sock #mysql的socket文件路径,通用二进制格式安装在/tmp
MYSQL_PORT              3306  #mysql服务器的端口号,由于使用的是socket,端口用不上
MYSQL_OPT               0 #mysql额外选项
MYSQL_DATABASE          extmail #mysql中的数据库
MYSQL_USER_TABLE        mailbox #mysql中的用户认证表
MYSQL_CRYPT_PWFIELD     password #哪个字段是存放用户的密码
MYSQL_UID_FIELD         2525 #邮件运行者的UID,即postfix
MYSQL_GID_FIELD         2525 #GID
MYSQL_LOGIN_FIELD       username #哪个字段是存放用户名
MYSQL_HOME_FIELD        concat('/var/mailbox/',homedir) #mysql存放用户的家目录,即存邮件                                                          路径,homedir是一个变量
MYSQL_NAME_FIELD        name #用户的全名在哪个字段上
MYSQL_MAILDIR_FIELD     concat('/var/mailbox/',maildir) #用户的邮箱目录

#配置完成,启动服务
[root@mail courier-authlib-0.66.3]# service courier-authlib start
Starting Courier authentication services: authdaemond

#验证服务启动情况
[root@mail courier-authlib-0.66.3]# ps aux | grep auth
root     20186  0.0  0.0   4068   520 ?        S    16:35   0:00 /usr/local/courier-authlib/sbin/courierlogger -pid=/usr/local/courier-authlib/var/spool/authdaemon/pid -start /usr/local/courier-authlib/libexec/courier-authlib/authdaemond
root     20187  0.0  0.1  55936  2220 ?        S    16:35   0:00 /usr/local/courier-authlib/libexec/courier-authlib/authdaemond
root     20188  0.0  0.0  55936   728 ?        S    16:35   0:00 /usr/local/courier-authlib/libexec/courier-authlib/authdaemond
root     20189  0.0  0.0  55936   728 ?        S    16:35   0:00 /usr/local/courier-authlib/libexec/courier-authlib/authdaemond
root     20190  0.0  0.0  55936   728 ?        S    16:35   0:00 /usr/local/courier-authlib/libexec/courier-authlib/authdaemond
root     20191  0.0  0.0  55936   728 ?        S    16:35   0:00 /usr/local/courier-authlib/libexec/courier-authlib/authdaemond
root     20192  0.0  0.0  55936   728 ?        S    16:35   0:00 /usr/local/courier-authlib/libexec/courier-authlib/authdaemond
root     20193  0.0  0.0  55936   728 ?        S    16:35   0:00 /usr/local/courier-authlib/libexec/courier-authlib/authdaemond
root     20194  0.0  0.0  55936   728 ?        S    16:35   0:00 /usr/local/courier-authlib/libexec/courier-authlib/authdaemond
root     20195  0.0  0.0  55936   728 ?        S    16:35   0:00 /usr/local/courier-authlib/libexec/courier-authlib/authdaemond
root     20196  0.0  0.0  55936   728 ?        S    16:35   0:00 /usr/local/courier-authlib/libexec/courier-authlib/authdaemond
root     20197  0.0  0.0  55936   728 ?        S    16:35   0:00 /usr/local/courier-authlib/libexec/courier-authlib/authdaemond
root     20199  0.0  0.0 103248   876 pts/3    R+   16:35   0:00 grep auth

#创建虚拟用户邮箱所在的目录,并将其权限给予postfix用户
[root@mail postfix-3.0.1]# mkdir -pv /var/mailbox
mkdir: created directory `/var/mailbox'
[root@mail postfix-3.0.1]# chown postfix /var/mailbox/

#接下来重新配置SMTP 认证,编辑 /usr/lib/sasl2/smtpd.conf ,确保其为以下内容:
pwcheck_method: authdaemond  #authdaemond是courier-authlib的主进程
log_level: 3
mech_list:PLAIN LOGIN
authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket #socket的路径

#注意:使用虚拟域的时候只能使用maildir邮箱格式

让postfix启用支持虚拟域和虚拟用户:

1、编辑/etc/postfix/main.cf,添加如下内容:
########################Virtual Mailbox Settings########################
virtual_mailbox_base = /var/mailbox  #用户邮件存放路径
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf #用户帐户映射表,文件由exmail提供,复制到相当目录中即可
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    #指定的一个MDA,即投递代理为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  #如果mailbox有限制覆盖postfix中的限定
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    #超限是否弹回

配置httpd服务

[root@mail docs]# yum install httpd -y

配置extman:

#使用extman源码目录下docs目录中的extmail.sql和init.sql建立数据库
[root@mail docs]# mysql -uroot -p < extmail.sql
[root@mail docs]# mysql -uroot < init.sql 

说明:
1、启用虚拟域以后,需要取消中心域,即注释掉myhostname, mydestination, mydomain, myorigin几个指令;当然,你也可以把mydestionation的值改为你自己需要的。
2、对于MySQL-5.1以后版本,其中的服务脚本extmail.sql执行会有语法错误;可先使用如下命令修改extmail.sql配置文件,而后再执行。修改方法如下:
# sed -i 's@TYPE=MyISAM@ENGINE=InnoDB@g' extmail.sql #在5.1以后的Mysql不支持myisam引擎

#授予用户extmail访问extmail数据库的权限
mysql> GRANT all privileges on extmail.* TO extmail@localhost IDENTIFIED BY 'extmail';
mysql> GRANT all privileges on extmail.* TO extmail@127.0.0.1 IDENTIFIED BY 'extmail';

配置dovecot-2.0.9-8服务:

#需要安装dovecot-devel包
yum install dovecot-devel
#配置
vim /etc/dovecot/dovecot.conf
protocols = imap pop3
vim /etc/dovecot/conf.d/10-mail.conf
mail_location = maildir:/var/mailbox/%d/%n/Maildir#用户邮件存放路径 %d表示域,%n表示用户
#!include auth-system.conf.ext  #禁用系统认证
!include auth-sql.conf.ext    #开启sql认证
vim /etc/dovecot/dovecot-sql.conf.ext
connect = host=localhost dbname=extmail user=extmail password=extmail #mysql为localhost,数据库为extmail,数据库用户:extmail 数据库密码:extmail
default_pass_scheme = CRYPT #密码加密机制
password_query = SELECT username AS user,password AS password FROM mailbox WHERE username = '%u'  #做验证时的查询语句
user_query = SELECT maildir, uidnumber AS uid, gidnumber AS gid FROM mailbox WHERE username = '%u'  #存放邮件的查询语句

安装extmail-1.2

说明:如果extmail的放置路径做了修改,那么配置文件webmail.cf中的/var/www路径必须修改为你所需要的位置。本文使用了默认的/var/www,所以,以下示例中并没有包含路径修改的相关内容。
# tar zxvf extmail-1.2.tar.gz
# mkdir -pv /var/www/extsuite
# mv extmail-1.2 /var/www/extsuite/extmail
# cp /var/www/extsuite/extmail/webmail.cf.default  /var/www/extsuite/extmail/webmail.cf

修改主配置文件
#vi /var/www/extsuite/extmail/webmail.cf

部分修改选项的说明:

SYS_MESSAGE_SIZE_LIMIT = 5242880
用户可以发送的最大邮件

SYS_USER_LANG = en_US
语言选项,可改作:
SYS_USER_LANG = zh_CN

SYS_MAILDIR_BASE = /home/domains
此处即为您在前文所设置的用户邮件的存放目录,可改作:
SYS_MAILDIR_BASE = /var/mailbox

SYS_MYSQL_USER = db_user
SYS_MYSQL_PASS = db_pass
以上两句句用来设置连接数据库服务器所使用用户名、密码和邮件服务器用到的数据库,这里修改为:
SYS_MYSQL_USER = extmail
SYS_MYSQL_PASS = extmail

SYS_MYSQL_HOST = localhost
指明数据库服务器主机名,这里默认即可

SYS_MYSQL_TABLE = mailbox
SYS_MYSQL_ATTR_USERNAME = username
SYS_MYSQL_ATTR_DOMAIN = domain
SYS_MYSQL_ATTR_PASSWD = password

以上用来指定验正用户登录里所用到的表,以及用户名、域名和用户密码分别对应的表中列的名称;这里默认即可

SYS_AUTHLIB_SOCKET = /var/spool/authdaemon/socket
此句用来指明authdaemo socket文件的位置,这里修改为:
SYS_AUTHLIB_SOCKET = /usr/local/courier-authlib/var/spool/authdaemon/socket

配置apache服务:

#首先关闭中心主机,并添加如下
User postfix
Group postfix
<VirtualHost *:80>
        ServerName mail.btsbox.com
        DocumentRoot /var/www/extsuite/extmail/html/
        ScriptAlias /extmail/cgi /var/www/extsuite/extmail/cgi
        Alias /extmail /var/www/extsuite/extmail/html
        SuexecUserGroup postfix postfix   #suexec可以让虚拟网站以另一个用户和组运行,如果需要指定此项,就不需要更改中心主机的user,group
</VirtualHost>

修改 cgi执行文件属主为apache运行身份用户:
# chown -R postfix.postfix /var/www/extsuite/extmail/cgi/

依赖关系的解决

extmail将会用到perl的Unix::syslogd功能,您可以去http://search.cpan.org搜索下载原码包进行安装。
# tar zxvf Unix-Syslog-0.100.tar.gz
# cd Unix-Syslog-0.100
# perl Makefile.PL
# make
# make install

5、启动apache服务
# service httpd start
# chkconfig httpd on


错误A:


Can't locate CGI.pm in @INC (@INC contains: /var/www/extsuite/extmail/libs /usr/local/lib/perl5 /usr/local/share/perl5 /usr/lib/perl5/vendor_perl

/usr/share/perl5/vendor_perl /usr/lib/perl5 /usr/share/perl5) at /var/www/extsuite/extmail/libs/Ext/CGI.pm line 20. BEGIN failed--compilation aborted at

/var/www/extsuite/extmail/libs/Ext/CGI.pm line 20. Compilation failed in require at /var/www/extsuite/extmail/libs/Ext/App.pm line 23. BEGIN failed--compilation

aborted at /var/www/extsuite/extmail/libs/Ext/App.pm line 23. Compilation failed in require at /var/www/extsuite/extmail/libs/Ext/App/Login.pm line 16. BEGIN failed--

compilation aborted at /var/www/extsuite/extmail/libs/Ext/App/Login.pm line 16. Compilation failed in require at /var/www/extsuite/extmail/cgi/index.cgi line 20.

解决办法:安装perl-CGI和perl-CGI-Session

# yum install perl-CGI 

#yum install perl-CGI-Session


安装Extman-1.1


1、安装及基本配置

# tar zxvf  extman-1.1.tar.gz
# mv extman-1.1 /var/www/extsuite/extman
#修改配置文件以符合本例的需要:
# cp /var/www/extsuite/extman/webman.cf.default  /var/www/extsuite/extman/webman.cf
# vi /var/www/extsuite/extman/webman.cf
SYS_MAILDIR_BASE = /home/domains

#此处即为您在前文所设置的用户邮件的存放目录,可改作:
SYS_MAILDIR_BASE = /var/mailbox
SYS_DEFAULT_UID = 1000
SYS_DEFAULT_GID = 1000
此两处后面设定的ID号需更改为前而创建的postfix用户和postfix组的id号,本文使用的是2525,因此,上述两项需要修改为:
SYS_DEFAULT_UID = 2525
SYS_DEFAULT_GID = 2525

SYS_MYSQL_USER = webman
SYS_MYSQL_PASS = webman
修改为:
SYS_MYSQL_USER = extmail
SYS_MYSQL_PASS = extmail

#而后修改cgi目录的属主:
# chown -R postfix.postfix /var/www/extsuite/extman/cgi/

在apache的主配置文件中Extmail的虚拟主机部分,添加如下两行:
ScriptAlias /extman/cgi /var/www/extsuite/extman/cgi
Alias /extman /var/www/extsuite/extman/html

创建其运行时所需的临时目录,并修改其相应的权限:
#mkdir  -pv  /tmp/extman
#chown postfix.postfix  /tmp/extman

修改
SYS_CAPTCHA_ON = 1
为
SYS_CAPTCHA_ON = 0



好了,到此为止,重新启动apache服务器后,您的Webmail和Extman已经可以使用了,可以在浏览器中输入指定的虚拟主机的名称进行访问,如下:

http://mail.magedu.com


选择管理即可登入extman进行后台管理了。默认管理帐号为:root@extmail.org  密码为:extmail*123*


说明:

(1) 如果您安装后无法正常显示校验码,安装perl-GD模块会解决这个问题。如果想简单,您可以到以下地址下载适合您的平台的rpm包,安装即可:  http://dries.ulyssis.org/rpm/packages/perl-GD/info.html

(2) extman-1.1自带了图形化显示日志的功能;此功能需要rrdtool的支持,您需要安装此些模块才可能正常显示图形日志。


邮件加密:

smtp-->smtps

    25-->465


S/MIME

    security/MIME

        USER<-->USER


实现S/MIME的功能有如下:

    OpenSSL,GPG(PGP)

        GPG:GUN privacy Guard,是PGP技术的一种实现

pops,imaps:支持基于openssl实现


pop3:995/tcp

imaps: 993/tcp


配置doveoct的pops


#创建CA并生成证书
[root@mail conf.d]# cd /etc/pki/CA/
[root@mail CA]# (umask 077;openssl genrsa -out private/cakey.pem 2048)  #创建CA key
Generating RSA private key, 2048 bit long modulus
......................................................+++
......................................................................................................................+++
e is 65537 (0x10001)
#创建自签证书
[root@mail CA]# openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 3657
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:ShangHai
Locality Name (eg, city) [Default City]:ShangHai
Organization Name (eg, company) [Default Company Ltd]:ogilvy
Organizational Unit Name (eg, section) []:Tech
Common Name (eg, your name or your server's hostname) []:ca.btsbox.com
Email Address []:admin@btsbox.com
[root@mail CA]# cd /etc/dovecot/^C
[root@mail CA]# cd /etc/dovecot/
[root@mail dovecot]# mkdir ssl
[root@mail dovecot]# cd ssl/
[root@mail ssl]# (umask 077;openssl genrsa 1024 -out dovecot.key)
Generating RSA private key, 1024 bit long modulus
......++++++
..........................................++++++
e is 65537 (0x10001)
-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQDdivw4Vgw/HY1R3KQ+01D+NwrsZwMdvipNHjf640buvhUB85Y5
MdjEoDkh4SikTV7tUIkyBeoq78LwjaPu2DUNyoZHNzuhWnEY6kpXhqWbJn+zX5/Y
cuTI/rRSPzn67X4jNPoFIghxg9nfl/n60GqJKpJ9a2+ig5osC1m2+9sigwIDAQAB
AoGBALMzIA8lsyQ+cDg+Q/C5l3L57PEJ5iBh2O+mONvMiWzF/lIkyWecJV3uyCfa
a7hzCQzmrwLye9adN87Ck064PjhXQsoGuXQwOW8EcCQam+fyHQNjwztNw0Zwfr2V
al7IOTLzhWM+JQyt9K30dz2P2MpdUXDzyTw3z7QqMEGPSp25AkEA8UdqGm6h1ok6
ETECGDqPkV3y7Ah/ccUnLsJQjJVTo4+xK5V3yM33rr9rwHniAqkhZtLgHxKB73Ze
HAlkba6hLwJBAOsPTzCc09ALZcze5d+dPfDzCV+SO7Xn/ADXCQXf2n/b6j8Dsb0d
KKTli1v2ydsT1+XX7tQO5PjHzcB392vQNu0CQEsfVhzWt1LptQenP6S1jv/OxZTR
7IRKwzFe1N+AmuMBGUOdrQb7ghOJjA4IpOL5L+oo3BkwlP4u14xZLEiuJ4cCQHri
DP8X7W9klfqNSFUnadtN4seQtiB5v3dc8z2b8ilHeWUp9EAuPzI9QiZ4lLwv2n0w
7ozzoGYiZgDJdpJpTl0CQH9SONpdnf6EQ3FUEWohWF+6aPVvB7fPpkSdeCI6C0FS
kSErVVG1AKLnteKzvSXBQiETqYk4k2tQZ8kz59tBef4=
-----END RSA PRIVATE KEY-----
#创建CA所需文件及CA序列
[root@mail CA]# touch index.txt
[root@mail CA]# echo 01 > serial
#创建dovecot ssl所需目录
[root@mail dovecot]# mkdir ssl
#创建dovecot的key
[root@mail ssl]# (umask 077;openssl genrsa 1024 > dovecot.key)
Generating RSA private key, 1024 bit long modulus
.++++++
.......++++++
e is 65537 (0x10001)
#导出dovecot key的签署文件
[root@mail ssl]# openssl req -new -key dovecot.key -out dovecot.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:ShangHai
Locality Name (eg, city) [Default City]:ShangHai
Organization Name (eg, company) [Default Company Ltd]:ogilvy
Organizational Unit Name (eg, section) []:Tech
Common Name (eg, your name or your server's hostname) []:mail.btsbox.com
Email Address []:postfix@btsbox.com

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
#到CA服务器中签署公钥证书
[root@mail ssl]# openssl ca -in dovecot.csr -out dovecot.crt -days 3657
Using configuration from /etc/pki/tls/openssl.cnf
Check that the request matches the signature
Signature ok
Certificate Details:
        Serial Number: 1 (0x1)
        Validity
            Not Before: Jul  2 02:28:38 2015 GMT
            Not After : Jul  6 02:28:38 2025 GMT
        Subject:
            countryName               = CN
            stateOrProvinceName       = ShangHai
            organizationName          = ogilvy
            organizationalUnitName    = Tech
            commonName                = mail.btsbox.com
            emailAddress              = postfix@btsbox.com
        X509v3 extensions:
            X509v3 Basic Constraints: 
                CA:FALSE
            Netscape Comment: 
                OpenSSL Generated Certificate
            X509v3 Subject Key Identifier: 
                95:B8:9F:C9:55:0B:D5:F5:77:62:F4:23:26:90:D7:48:EE:04:9B:4D
            X509v3 Authority Key Identifier: 
                keyid:61:13:E2:C0:BE:54:40:A6:9E:26:F8:E3:6E:2D:61:00:1E:08:9A:FB

Certificate is to be certified until Jul  6 02:28:38 2025 GMT (3657 days)
Sign the certificate? [y/n]:y


1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated

#证书文件,注意修改权限
[root@mail ssl]# ls -l
total 12
-rw-r--r--. 1 root root 3872 Jul  2 10:28 dovecot.crt
-rw-r--r--. 1 root root  708 Jul  2 10:26 dovecot.csr
-rw-------. 1 root root  887 Jul  2 10:25 dovecot.key

#在dovecot的认证文件中配置ssl设置
[root@mail conf.d]# cat 10-ssl.conf
##
## SSL settings
##

# SSL/TLS support: yes, no, required. <doc/wiki/SSL.txt>
#ssl = yes
ssl = yes    #启用ssl认证

# PEM encoded X.509 SSL/TLS certificate and private key. They're opened before
# dropping root privileges, so keep the key file unreadable by anyone but
# root. Included doc/mkcert.sh can be used to easily generate self-signed
# certificate, just make sure to update the domains in dovecot-openssl.cnf
#ssl_cert = </etc/pki/dovecot/certs/dovecot.pem
#ssl_key = </etc/pki/dovecot/private/dovecot.pem
ssl_cert = </etc/dovecot/ssl/dovecot.crt    #dovecot的公钥文件位置
ssl_key = </etc/dovecot/ssl/dovecot.key    #dovecot的私钥文件位置
# If key file is password protected, give the password here. Alternatively
# give it when starting dovecot with -p parameter. Since this file is often
# world-readable, you may want to place this setting instead to a different
# root owned 0600 file by using ssl_key_password = <path.
#ssl_key_password =    #dovecot key的密码设置

# PEM encoded trusted certificate authority. Set this only if you intend to use
# ssl_verify_client_cert=yes. The file should contain the CA certificate(s)
# followed by the matching CRL(s). (e.g. ssl_ca = </etc/pki/dovecot/certs/ca.pem)
#ssl_ca = 

# Request client to send a certificate. If you also want to require it, set
# auth_ssl_require_client_cert=yes in auth section.
#ssl_verify_client_cert = no

# Which field from certificate to use for username. commonName and
# x500UniqueIdentifier are the usual choices. You'll also need to set
# auth_ssl_username_from_cert=yes.
#ssl_cert_username_field = commonName

# How often to regenerate the SSL parameters file. Generation is quite CPU
# intensive operation. The value is in hours, 0 disables regeneration
# entirely.
#ssl_parameters_regenerate = 168

# SSL protocols to use
#ssl_protocols = !SSLv2 !SSLv3

# SSL ciphers to use
#ssl_cipher_list = ALL:!LOW:!SSLv2:!EXP:!aNULL

#监听系统端口
[root@mail conf.d]# netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 0.0.0.0:993                 0.0.0.0:*                   LISTEN      15696/dovecot       
tcp        0      0 0.0.0.0:995                 0.0.0.0:*                   LISTEN      15696/dovecot       
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      12452/mysqld        
tcp        0      0 0.0.0.0:110                 0.0.0.0:*                   LISTEN      15696/dovecot       
tcp        0      0 0.0.0.0:143                 0.0.0.0:*                   LISTEN      15696/dovecot       
tcp        0      0 10.189.9.204:53             0.0.0.0:*                   LISTEN      15093/named         
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      1116/sshd           
tcp        0      0 127.0.0.1:953               0.0.0.0:*                   LISTEN      15093/named         
tcp        0      0 0.0.0.0:25                  0.0.0.0:*                   LISTEN      14053/master        
tcp        0      0 :::993                      :::*                        LISTEN      15696/dovecot       
tcp        0      0 :::995                      :::*                        LISTEN      15696/dovecot       
tcp        0      0 :::110                      :::*                        LISTEN      15696/dovecot       
tcp        0      0 :::143                      :::*                        LISTEN      15696/dovecot       
tcp        0      0 :::80                       :::*                        LISTEN      13190/httpd         
tcp        0      0 :::22                       :::*                        LISTEN      1116/sshd           
udp        0      0 10.189.9.204:53             0.0.0.0:*                               15093/named  

#使用openssl s_client工具验证pop3s的工作状态
[root@mail conf.d]# openssl s_client -connect mail.btsbox.com:995
CONNECTED(00000003)
depth=0 C = CN, ST = ShangHai, O = ogilvy, OU = Tech, CN = mail.btsbox.com, emailAddress = postfix@btsbox.com
verify error:num=20:unable to get local issuer certificate
verify return:1
depth=0 C = CN, ST = ShangHai, O = ogilvy, OU = Tech, CN = mail.btsbox.com, emailAddress = postfix@btsbox.com
verify error:num=27:certificate not trusted
verify return:1
depth=0 C = CN, ST = ShangHai, O = ogilvy, OU = Tech, CN = mail.btsbox.com, emailAddress = postfix@btsbox.com
verify error:num=21:unable to verify the first certificate
verify return:1
---
Certificate chain
 0 s:/C=CN/ST=ShangHai/O=ogilvy/OU=Tech/CN=mail.btsbox.com/emailAddress=postfix@btsbox.com
   i:/C=CN/ST=ShangHai/L=ShangHai/O=ogilvy/OU=Tech/CN=ca.btsbox.com/emailAddress=admin@btsbox.com
---
Server certificate
-----BEGIN CERTIFICATE-----
MIIDfDCCAmSgAwIBAgIBATANBgkqhkiG9w0BAQUFADCBjDELMAkGA1UEBhMCQ04x
ETAPBgNVBAgMCFNoYW5nSGFpMREwDwYDVQQHDAhTaGFuZ0hhaTEPMA0GA1UECgwG
b2dpbHZ5MQ0wCwYDVQQLDARUZWNoMRYwFAYDVQQDDA1jYS5idHNib3guY29tMR8w
HQYJKoZIhvcNAQkBFhBhZG1pbkBidHNib3guY29tMB4XDTE1MDcwMjAyMjgzOFoX
DTI1MDcwNjAyMjgzOFowfTELMAkGA1UEBhMCQ04xETAPBgNVBAgMCFNoYW5nSGFp
MQ8wDQYDVQQKDAZvZ2lsdnkxDTALBgNVBAsMBFRlY2gxGDAWBgNVBAMMD21haWwu
YnRzYm94LmNvbTEhMB8GCSqGSIb3DQEJARYScG9zdGZpeEBidHNib3guY29tMIGf
MA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCwp4HeOf9oGDCkIj83XX8bjnkpJFWe
v1V29fLEKotEeLCV24WdwzIhoLtuNRDTXvu6ThypYGR3ij7jwNR7LyYfdE7fMlSN
L+KGY0pAeOV3Fszf1+1+Ako0DAtNdu7JQtTwnvFXTK+yRBwHE2s5tEgt1ER4L6C+
sEc70/gg84mWKwIDAQABo3sweTAJBgNVHRMEAjAAMCwGCWCGSAGG+EIBDQQfFh1P
cGVuU1NMIEdlbmVyYXRlZCBDZXJ0aWZpY2F0ZTAdBgNVHQ4EFgQUlbifyVUL1fV3
YvQjJpDXSO4Em00wHwYDVR0jBBgwFoAUYRPiwL5UQKaeJvjjbi1hAB4ImvswDQYJ
KoZIhvcNAQEFBQADggEBAIadsaPCqzHyEpelrNKuEd9l3MoSqq0dzLYtB1SlUeD2
ETT8DWahW991fqRrDBIQtRgz+VWuTSOMK4QrBpkofvtEUTMuhAoH52osK7rQv7Rq
2RV8nnLL8isedWdUwE6k+X46yO1Tkkc2pVLAWv4taMOggnQy25ivPSz/FZDJ1+uY
X4fAHJrjYALjMfg8eZJKxMnDYuYe2ElzI55ATkFAKquunUSmof9xOiQBdJTM+fz7
Sg2Po/reIcvw+okc7RNzhLeChJpFMQTwolGyZWfkP9tVyonHFaFpXkqF0BS/QBrc
C647rDdRpVj1svNvt49meg0KogBfdaPjffTJa5tTiQU=
-----END CERTIFICATE-----
subject=/C=CN/ST=ShangHai/O=ogilvy/OU=Tech/CN=mail.btsbox.com/emailAddress=postfix@btsbox.com
issuer=/C=CN/ST=ShangHai/L=ShangHai/O=ogilvy/OU=Tech/CN=ca.btsbox.com/emailAddress=admin@btsbox.com
---
No client certificate CA names sent
Server Temp Key: DH, 1024 bits
---
SSL handshake has read 1613 bytes and written 439 bytes
---
New, TLSv1/SSLv3, Cipher is DHE-RSA-AES256-GCM-SHA384
Server public key is 1024 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
SSL-Session:
    Protocol  : TLSv1.2
    Cipher    : DHE-RSA-AES256-GCM-SHA384
    Session-ID: AF9DFEF321090081700CCB0CBA90F818DA05071796CA227B64BE583C61CB33E2
    Session-ID-ctx: 
    Master-Key: A6859690FFB09B01623A28DF6C6E5DB874E24454D86BF72736D769EE9EF82D336294521B9C55329DFE72B5A7CB137633
    Key-Arg   : None
    Krb5 Principal: None
    PSK identity: None
    PSK identity hint: None
    TLS session ticket lifetime hint: 300 (seconds)
    TLS session ticket:
    0000 - b8 da 5e db ba 09 d6 68-c3 71 68 95 29 2a d7 44   ..^....h.qh.)*.D
    0010 - 07 ee 28 f9 e8 d1 4f 9c-0d ae 6e 99 9f 4f c5 f6   ..(...O...n..O..
    0020 - dd b1 95 7e 72 36 69 f6-b2 f8 1c 5b 14 e5 74 bc   ...~r6i....[..t.
    0030 - 34 3e 48 53 59 c1 9e 8c-b5 d8 cb 21 ae 13 64 4b   4>HSY......!..dK
    0040 - 82 3a 19 da e7 73 a7 f7-01 24 87 14 f9 f1 4d e8   .:...s...$....M.
    0050 - 8f e4 c1 49 4a c1 f5 c0-9e 2e 38 5b e3 ba e2 ec   ...IJ.....8[....
    0060 - 62 de 2f 1e bb 80 34 87-55 26 0e b9 66 35 d5 77   b./...4.U&..f5.w
    0070 - b5 0c d5 1f 10 c5 b0 eb-07 bd d4 9e 5c 39 65 a5   ............\9e.
    0080 - b7 ec 81 0b 57 d8 69 7d-fc b3 88 f3 41 de 7c 46   ....W.i}....A.|F
    0090 - 38 7d 00 9b 5f d4 e3 5d-ae 7a 5e 81 48 5f 9d      8}.._..].z^.H_.
    00a0 - <SPACES/NULS>

    Start Time: 1435806118
    Timeout   : 300 (sec)
    Verify return code: 21 (unable to verify the first certificate)
---
+OK Dovecot ready.
user hadoop
+OK
pass hadoop
-ERR Authentication failed.
user hadoop@btsbox.com
+OK
pass hadoop
+OK Logged in.
list
+OK 0 messages:
.
quit
+OK Logging out.


对Https pop3s imaps等基于SSL会话,需要远程测试的时候,需使用:

    openssl s_client -connect SERVER:PORT -CAfile /path/to/ca_cert


协议报文分析器:

    sniffer:商业工具

    tcpdump,wireshark(GUI),tshark(CLI)


Tcpdump工具的使用:

    语法:

    tcpdump [options] [protocol][direction][Host(s)][Value][logical operations][Other exp             ression]

tcpdump ip src host 172.16.100.1
tcpdump src or dst port 21
tcpdump udp dst port 53
tcpdump src or dst port 21 AND src host 172.16.100.1

protocol(协议)

values(取值):ether,fddi,ip,arp,rarp,decnet,lat,sca,moprc,mopdl,tcp and udp

if no protocol is specified,all the protocols are used.

ether:以太网侦

fddi:分布式光纤通道

Direction(流向)


values(取值):src,dst,src and dst,src or dst 

if no source or destination is specified,the "src or dst" keywords are applied(默认是src or dst)

for example: "host 10.2.2.2" is equivalent to "src or dst host 10.2.2.2"


Host主机:

values(替代关键字):net,port,host,portrange

if no host(s) is specified the "host" keyword is used. 默认如果此段没有指定关键字,即host.

for example,"src 10.1.1.1" is equivalent to "src host 10.1.1.1".


logical operations:

(1)AND

and or &&

(2)OR

or or ||

(3)EXCEPT

net or !


常用选项:


-i any : Listen on all interfaces just to see if you're seeing any traffic.

-n : Don't resolve hostnames.不反解主机名

-nn : Don't resolve hostnames or port names.

-X : Show the packet's contents in both hex and ASCII.显示报文以16进制和ascii格式

-XX : Same as -X, but also shows the ethernet header.

-v, -vv, -vvv : Increase the amount of packet information you get back.

-c # : Only get x number of packets and then stop.

-s : Define the snaplength (size) of the capture in bytes. Use -s0 to get everything, unless you are intentionally capturing less.

-S : Print absolute sequence numbers.

-e : Get the ethernet header as well.

-q : Show less protocol information.

-E : Decrypt IPSEC traffic by providing an encryption key.

-A :Display Captured Packets in ASCII

-w /path/to/some_file : Capture the packets and write into a file 

-r /path/from/some_file : Reading the packets from a saved file 

-tttt : Capture packets with proper readable timestamp


反垃圾邮件组件:

    内容过滤器:

        Apache:Spamassassin(perl开发,垃圾邮件分拣器,利用、特征码库分析)

    实时过虑表(realtime black list)

        实时黑名单

    病毒邮件网关:

        clamav:开源杀毒软件

            病毒邮件服务器网关


邮件服务器的呼叫器:

    反垃圾组件与邮件系统的连接器

        MIMEDefang

        Mailscanner

        Amavisd-new(基于smtp模式开发,一般都基于此插件过滤邮件,也基于perl开发)


Postfix+maildrop-2.8.3的实现:

#输入courier-authlib的库文件和头文件,courier-maildorp依赖于authlib
[root@mail ~]# cat /etc/ld.so.conf.d/courier-authlib.conf 
/usr/local/courier-authlib/lib/courier-authlib/
[root@mail ld.so.conf.d]# ldconfig -v
#输入courier-authlib的头文件,需要直接将头文件单个连接到/usr/include目录中
[root@mail ld.so.conf.d]# ln -sv /usr/local/courier-authlib/include/* /usr/include/
#创建maildrop运行时所需要的用户和组,GID,UID一般为1001
[root@mail ~]# groupadd -g 1001 vmail
[root@mail ~]# useradd -g 1001 -u 1001 -M -s /sbin/nologin vmail
#安装courier-authlib所需的依赖软件pcre--devel包
[root@mail ~]# yum install pcre-devel -y

#安装Maildrop软件
[root@mail ~]# tar xf maildrop-2.8.3.tar.bz2 
[root@mail ~]# cd maildrop-2.8.3
# ./configure \
     --enable-sendmail=/usr/sbin/sendmail \ 
     --enable-trusted-users='root vmail' \
     --enable-syslog=1 --enable-maildirquota \
     --enable-maildrop-uid=1001 \
     --enable-maildrop-gid=1001 \
     --with-trashquota --with-dirsync

--enable-sendmail=/usr/sbin/sendmail:开启客户端支持sendmail
--enable-trusted-users='root vmail':信任传送邮件的用户root,vmail
--enable-syslog=1:使用syslog记录日志
--enable-maildirquota:开启maildrop磁盘配额
--enable-maildrop-uid=1001:指定maildrop运行的用户   
--enable-maildrop-gid=1001:指定maildrop运行的组
--with-dirsync:支持目录自动同步     
--with-trashquota:回收站配额
# make
# make install

注:maildrop安装的时候没有指定安装路径,默认路径为/usr/local/bin/maildrop,即在postfix中的master.cf中调用maildrop,已经指定的路径

[root@mail maildrop-2.8.3]# maildrop -v
maildrop 2.8.3 Copyright 1998-2015 Double Precision, Inc.
GDBM/DB extensions enabled.
Courier Authentication Library extension enabled.
Maildir quota extension are now always enabled.
This program is distributed under the terms of the GNU General Public
License. See COPYING for additional information.

#添加maildrop的配置文件
[root@mail maildrop-2.8.3]# cat /etc/maildroprc 
logfile "/var/log/maildrop.log"

#准备maildrop的日志文件
[root@mail maildrop-2.8.3]# touch /var/log/maildrop.log
[root@mail maildrop-2.8.3]# chown -R vmail.vmail /var/log/maildrop.log

#启用postfix对maildrop的连接
[root@mail courier-unicode-1.3]#  vim /etc/postfix/master.cf
maildrop  unix  -       n       n       -       -       pipe
  flags=DRhu user=vmail argv=/usr/local/bin/maildrop -d ${recipient}#参数行必须以空格开始
# vi /etc/postfix/main.cf
 virtual_transport = virtual
 修改为:
 virtual_transport = maildrop
 
将下面两项指定的UID和GID作相应的修改:
 virtual_uid_maps = static:2525
 virtual_gid_maps = static:2525
 修改为:
 virtual_uid_maps = static:1001
 virtual_gid_maps = static:1001

#修改courier-authlib对sql的连接用户
 # vi /etc/authmysqrc
 MYSQL_UID_FIELD  '2525'
 MYSQL_GID_FIELD  '2525'
 更改为:
 MYSQL_UID_FIELD  '1001'
 MYSQL_GID_FIELD  '1001'
 
 
 #修改httpd的运行用户和组身份:
 [root@mail maildrop-2.8.3]# cat /etc/httpd/conf/httpd.conf | grep vmail
User vmail
Group vmail

#修改用户邮箱存放位置及extman的运行临时目录权限
[root@mail maildrop-2.8.3]# chown -R vmail.vmail /var/mailbox/
[root@mail maildrop-2.8.3]# chown -R vmail.vmail /tmp/extman/

#修改extman的运行身份
[root@mail maildrop-2.8.3]# cat /var/www/extsuite/extman/webman.cf | grep 1001
SYS_DEFAULT_UID = 1001
SYS_DEFAULT_GID = 1001

#重启apache、postfix、courier-authlib服务,由于maildrop是postfix的master.cf调用,故不需要单独启动,是由master.cf需要使用的时候