【实验名称】邮件服务器Postfix的配置

【实验目标】

熟悉邮件服务的基本原理

掌握Postfix服务器的基本配置

掌握dovecot服务器的安装于配置

掌握webmail应用系统的安装于配置

实现双域邮件服务器的收发

【实验原理】

常用的邮件服务器软件

  商业邮件系统 :

 Exchange:微软公司的重量级产品,与Windows系列软件产品相集成,协作性较好
 Notes/Domino:IBM公司的商业电子邮件和办公协作软件产品,功能丰富、强大,提供跨平台支持
 
开源邮件系统 :
 
 Sendmail:资格最古老,运行稳定,但安全性欠佳
 Qmail:有更好的执行效率,配置、管理也很方便
n Postfix:兼容Sendmail,采用模块化设计,在投递效率、稳定性、服务性能及安全性方面表现优秀
 
邮件系统的组成:
 
邮件系统中的角色 :
 
MUA:Mail User Agent ,邮件用户代理
MTA:Mail Transfer Agent ,邮件传输代理
 
邮件协议 :
 
邮件发送协议SMTP
Simple Mail Transfer Protocol ,简单邮件传输协议
 
邮件收取协议:
 
POP3 : Post Office Protocol V3,邮局协议第3版
IMAP4 : Internet Message Access Protocol V4,因特网消息访问协议第4版
 
Postfix的安装与主要目录:
 
安装:yum install postfix
配置文件目录:/etc/postfix/
服务程序目录:/usr/libexec/postfix/
邮件队列目录:/var/spool/postfix/*
incomingactivedeferred
hold、corrupt
邮件管理程序目录:/usr/sbin/*
postalias、postmap、
postconfpostfix
postqueue、postsuper
 
Postfix的配置文件:
 
/etc/postfix/master.cf
master主程序的配置文件
/etc/postfix/main.cf
postfix服务的配置文件
辅助配置工具 postconf
执行 postconf ,查看当前的有效配置
执行 postconf -n ,查看非默认配置
执行 postconf -d ,查看默认配置

 Postfix的日志文件: 

/var/log/maillog
记录了postfix服务的邮件传递等过程信息
常用分析方法
动态跟踪日志变化
 tail -f /var/log/maillog
关键词搜索
 egrep '(reject|warning|error|fatal|panic):' /var/log/maillog

【实验步骤】

一、修改主机名:

[root@rhel5 ~]# vi /etc/sysconfig/network    --------------------修改主机名
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=rhel5.xapc.com

NETWORKING=yes
NETWORKING_IPV6=no

[root@rhel5 ~]# vi /etc/hosts     -------------------------------修改主机配置文件
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1               rhel5.xapc.com rhel5 localhost.localdomain localhost
::1             localhost6.localdomain6 localhost6
127.0.0.1               gouzhongxing.xapc.com gouzhongxing localhost.localdomain"/etc/hosts" 4L, 222C written
 
[root@rhel5 ~]# vi /etc/selinux/config --------------------修改防火墙配置

SELINUX=disabled

[root@rhel5 ~]# service iptables save
Saving firewall rules to /etc/sysconfig/iptables: [  OK  ]
[root@rhel5 ~]# iptables -F
[root@rhel5 ~]#reboot

二、安装Postfix服务:

[root@gouzhongxing named]# yum install postfix   ------------------------------安装postfix服务

[root@gouzhongxing named]# postconf

[root@gouzhongxing named]# postfix start   ------------------------------启动postfix服务
postfix/postfix-script: starting the Postfix mail system
[root@gouzhongxing named]# netstat -ntl    -----------------------------查看运行端口

tcp        0      0 192.168.20.10:25            0.0.0.0:*                   LISTEN     
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN     

[root@gouzhongxing named]# useradd gou    -----------------------------新建邮件用户
[root@gouzhongxing named]# useradd zhong
[root@gouzhongxing named]# useradd xing
[root@gouzhongxing named]#
[root@gouzhongxing named]# passwd gou    -----------------------------设置口令
Changing password for user gou.
New UNIX password:
BAD PASSWORD: it is WAY too short
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@gouzhongxing named]# passwd zhong
Changing password for user zhong.
New UNIX password:
BAD PASSWORD: it is WAY too short
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@gouzhongxing named]# passwd xing
Changing password for user xing.
New UNIX password:
BAD PASSWORD: it is WAY too short
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@gouzhongxing named]# telnet localhost 25   ----------------------------使用telnet命令进行测试
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 gouzhongxing.xapc.com ESMTP Postfix
HELO localhost
250 gouzhongxing.xapc.com
MAIL FROM:gou@xapc.com
250 2.1.0 Ok
Rcpt to:zhong@xapc.com
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
Subject:111111111111111111
11111111111111111111111111
.
250 2.0.0 Ok: queued as 56F3D258059
QUIT
221 2.0.0 Bye
Connection closed by foreign host.
[root@gouzhongxing named]# ll ~zhong   -----------------------------查看用户的目录
total 4
drwx------ 5 zhong zhong 4096 Feb 17 01:52 Maildir
[root@gouzhongxing named]# ll ~zhong/Maildir/
total 12
drwx------ 2 zhong zhong 4096 Feb 17 01:52 cur
drwx------ 2 zhong zhong 4096 Feb 17 01:52 new
drwx------ 2 zhong zhong 4096 Feb 17 01:52 tmp
[root@gouzhongxing named]# ll ~zhong/Maildir/new/
total 4
-rw------- 1 zhong zhong 480 Feb 17 01:52 1013881936.Vfd00I10012fM499738.gouzhongxing.xapc.com
[root@gouzhongxing named]# cat ~zhong/Maildir/new/1013881936.Vfd00I10012fM499738.gouzhongxing.xapc.com
Return-Path: <gou@xapc.com>
X-Original-To: zhong@xapc.com
Delivered-To: zhong@xapc.com
Received: from localhost (gouzhongxing.xapc.com [127.0.0.1])
        by gouzhongxing.xapc.com (Postfix) with SMTP id 56F3D258059
        for <zhong@xapc.com>; Sun, 17 Feb 2002 01:51:08 +0800 (CST)
Subject:111111111111111111
Message-Id: <20020216175149.56F3D258059@gouzhongxing.xapc.com>
Date: Sun, 17 Feb 2002 01:51:08 +0800 (CST)
From: gou@xapc.com
To: undisclosed-recipients:;

11111111111111111111111111

 三、安装dovecot服务:


[root@gouzhongxing named]# yum install dovecot    ------------------------安装dovecot服务器

[root@gouzhongxing named]# vi /etc/dovecot.conf

ssl_disable = yes    -------------------禁用ssl机制
...............................................

protocols = imap pop3     -------------------支持的邮局协议

disable_plaintext_auth = no    -------------------允许明文密码认证
 
mail_location = maildir:~/Maildir  -------------------邮件存储格式及位置

[root@gouzhongxing named]# service dovecot start-------------------启动dovecot服务
Starting Dovecot Imap: [  OK  ]
[root@gouzhongxing named]# netstat -ntl  -------------------查看运行端口

tcp        0      0 :::110                      :::*                        LISTEN     
tcp        0      0 :::143                      :::*                        LISTEN     

[root@gouzhongxing named]# telnet localhost 110---------------------使用telnet命令进行收信测试
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
+OK Dovecot ready.
USER zhong
+OK
PASS 123
+OK Logged in.
LIST
+OK 1 messages:
1 493
.
RETR 1
+OK 493 octets
Return-Path: <gou@xapc.com>
X-Original-To: zhong@xapc.com
Delivered-To: zhong@xapc.com
Received: from localhost (gouzhongxing.xapc.com [127.0.0.1])
        by gouzhongxing.xapc.com (Postfix) with SMTP id 56F3D258059
        for <zhong@xapc.com>; Sun, 17 Feb 2002 01:51:08 +0800 (CST)
Subject:111111111111111111
Message-Id: <20020216175149.56F3D258059@gouzhongxing.xapc.com>
Date: Sun, 17 Feb 2002 01:51:08 +0800 (CST)
From: gou@xapc.com
To: undisclosed-recipients:;

11111111111111111111111111
.
QUIT 
+OK Logging out.
Connection closed by foreign host.
 

使用邮件客户端测试:

在Outlook Express 中设置邮件账号:

  对于用户gou需要设置邮件帐号为gou@xapc.com

SMTP服务器设置为gouzhongxing.xapc.com
POP3服务器设置为gouzhongxing.xapc.com
四、安装webmail应用系统:
添加webmail邮件界面: 
编译安装squirrelmail程序套件
下载源码包
 官方站点:http://www.squirrelmail.org 
 网页程序包:squirrelmail-1.4.20.tar.gz
 中文语言包:zh_CN-1.4.18-20090526.tar.gz
 
解包至Web服务的网页目录:
 
[root@gouzhongxing named]#  tar zxvf /media/squirrelmail-1.4.20.tar.gz -C /var/www/html/
[root@gouzhongxing named]#  cd /var/www/html
[root@gouzhongxing named]#  mv squirrelmail-1.4.20 webmail
[root@gouzhongxing named]# cd webmail
[root@gouzhongxing named]#  tar zxvf /media/zh_CN-1.4.18-20090526.tar.gz

创建及调整数据目录、附件目录:

  [root@gouzhongxing webmail]# mkdir -p attach data

 [root@gouzhongxing webmail]#chown -R apache:apache attach/ data/

 [root@gouzhongxing webmail]#chmod 730 attach/

建立并调整config.php配置文件:

 [root@gouzhongxing webmail]# cp config/config_default.php config/config.php

[root@gouzhongxing webmail]#  vi config/config.php
$squirrelmail_default_language = 'zh_CN';
$default_charset       = 'zh_CN.UTF-8';
$domain                 = 'xapc.com';
$smtpServerAddress = 'localhost';
$smtpPort = 25;
$imap_server_type    = 'dovecot';
$imapPort = 143;
$data_dir                 = '/usr/local/apache2/htdocs/webmail/data/';
$p_w_upload_dir      = '/usr/local/apache2/htdocs/webmail/attach/';
确认启动httpd服务程序:
在浏览器中访问webmail界面: