首先设置DNS服务器主配置文件

Vim /var/named/chroot/etc/named.conf
options  {
          directory     "/var/named";
};
zone "hanfangzhou.com" {
      type   master;
      file    "hanfangzhou.com.zone";
};                           
再设置 区域记录
Cp /usr/share/doc/bind-9.3.6/sample/var/named/localhost.zone /var/named/chroot/var/name/hanfangzhou.com.zone
Vim /var/named/chroot/var/named/hanfangzhou.com.zone  
@               IN SOA  @       root (
                                        42              ; serial (d. adams)
                                        3H              ; refresh
                                        15M             ; retry
                                        1W              ; expiry
                                        1D )            ; minimum
 
hanfangzhou.com.                IN NS           mail.hanfangzhou.com.
mail.hanfangzhou.com.           IN A            192.168.18.48
hanfangzhou.com.                IN MX 10        mail.hanfangzhou.com.
保存退出
重启DNS服务 service named restart 设置开机启动项 chkconfig named on
测试 [root@localhost named]# echo ""> /etc/resolv.conf
     [root@localhost named]# host mail.hanfangzhou.com
     mail.hanfangzhou.com has address 192.168.18.48
关闭sendmail服务 取消开机启动像
 service sendmail stop 
 chkconfig sendmail off
安装 postfix      yum install postfix -y
修改配置文件 vim /etc/postfix/main.cf
69 myhostname = mail.hanfangzhou.com
77 mydomain = hanfangzhou.com
93 myorigin = $mydomain
107 inet_interfaces = all
155 mydestination = $myhostname, localhost.$mydomain, localhost
255 mynetworks = 192.168.18.0/24, 127.0.0.0/8
287 relay_domains = hanfangzhou.com
保存退出
设置SMTP认证配置文件
vim /etc/sysconfig/saslauthd 
   MECH=shadow
保存退出
重启saslauthd服务
service saslauthd restart
检查防火墙和SElinux是否关闭
验证
[root@localhost ~]# useradd laogong
[root@localhost ~]# passwd laogong
Changing password for user laogong.
New UNIX password: 
BAD PASSWORD: it is WAY too short
Retype new UNIX password: 
passwd: all authentication tokens updated successfully.
[root@localhost ~]# testsaslauthd -u laogong -p '123'
0: OK "Success."
mail与smtp关联
vim /etc/postfix/main.cf
smtpd_sasl_auth_enable = yes 
smtpd_sasl_local_domain = ''
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
broken_sasl_auth_clients = yes 
smtpd_client_restrictions = permit_sasl_authenticated
smtpd_sasl_security_options = noanonymous
保存退出
重启postfix服务并设置开机启动项
service postfix restart         chkconfig postfix on
perl -MMIME::Base64 -e 'print encode_base64(laogong);'
bGFvZ29uZw==
perl -MMIME::Base64 -e 'print encode_base64(123);'
MTIz
链接mail服务器
[root@localhost ~]# telnet mail.hanfangzhou.com 25
Trying 192.168.18.48...
Connected to mail.hanfangzhou.com (192.168.18.48).
Escape character is '^]'.
220 mail.hanfangzhou.com ESMTP Postfix
ehlo hanfangzhou.com
250-mail.hanfangzhou.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
auth login
334 VXNlcm5hbWU6
bGFvZ29uZw==
334 UGFzc3dvcmQ6
MTIz
235 2.0.0 Authentication successful
yum安装dovecot
yum install dovecot -y
修改配置文件
vim /etc/dovecot.conf
 
protocols = pop3 pop3s
 
 
 protocol pop3 {
     listen = *:10100
#     ..
   }
保存退出
重启dovecot 并加载开机启动项
 /etc/init.d/dovecot restart    chkconfig dovecot on
安装 cyrus
yum install cyrus-imapd cyrus-imapd-devel -y
修改postfix主配置文件  vim /etc/postfix/main.cf
修改 456行 去掉注释符 mailbox_transport = lmtp:unix:/var/lib/imap/socket/lmtp
重启cyrus 并设置开机启动项
[root@localhost ~]# /etc/init.d//cyrus-imapd restart
/etc/sysconfig/i18n: line 1: [root@php~]#: command not found
正在关闭 cyrus-imapd:                                     [失败]
导出 cyrus-imapd 数据库:                                  [确定]
导入 cyrus-imapd 数据库:                                  [确定]
启动 cyrus-imapd:                                         [确定]
[root@localhost ~]# chkconfig cyrus-imapd on
设置cyrus后台密码为123
[root@localhost ~]# passwd cyrus
Changing password for user cyrus.
New UNIX password: 
BAD PASSWORD: it is WAY too short
Retype new UNIX password: 
passwd: all authentication tokens updated successfully.
重启 postfix服务  service postfix restart
添加laoyu用户
 [root@localhost ~]# cyradm -u cyrus localhost
IMAP Password: 
              localhost.localdomain> cm user.laoyu
localhost.localdomain> cm user.laoyu.Send
localhost.localdomain> cm user.laoyu.Trash
localhost.localdomain> cm user.laoyu.Drafts
localhost.localdomain> quit
安装 webmail  squirrelmail   yum install squirrelmail -y
设置 wenmail   /usr/share/squirrelmail/config/conf.pl 
重启HTTPD服务
配置完成