[关闭]
@sww4718168 2014-04-27T14:16:58.000000Z 字数 4936 阅读 3532

搭建邮件服务器粗体文本

使用postfix和dovecot软件包来搭建邮件服务器(RHEL5)


准备实验环境


配置DNS服务器

具体配置可以查看RHEL5中配置DNS服务器,这里只写出其中的不同之处。

[root@dns1 named]# cat test.com.zone 
8          IN      NS      dns1.test.com.
9          IN      MX 5    mail.test.com.  #MX是邮件记录,后面数字是服务器的优先级
10 dns1    IN      A       172.16.1.254
11 mail    IN      A       172.16.1.253

[root@dns1 named]# cat /etc/resolv.conf 
nameserver 172.16.1.254

在linux下可以使用如下命令查看邮件服务器的域名:

[root@dns1 named]# host -t mx test.com
test.com mail is handled by 5 mail.test.com.
[root@dns1 named]# host mail.test.com
mail.test.com has address 172.16.1.253

配置发件服务

[root@mail ~]# yum install postfix -y #安装postfix,这个包提供邮件的发送服务,使用tcp的25端口。
[root@mail ~]# cd /etc/postfix/    #postfix的配置文件目录
[root@mail postfix]# postconf -n > tmp #导出postfix的非默认配置
[root@mail postfix]# mv main.cf main.cf.bak #备份默认的配置文件
[root@mail postfix]# mv tmp main.cf    #因为默认的配置文件中有太多是默认配置,我们这样可以去掉这些默认配置,精简配置文件的内容。

修改配置文件

[root@mail postfix]# vim main.cf
  1. 8 #inet_interfaces = localhost #将第8行注释掉,这样它所监听的地址就会变为0.0.0.0:25
  2. ... #添加如下内容
  3. 21 myhostname = mail.test.com #邮件服务器主机名
  4. 22 mydomain = test.com #邮件服务器所在区域
  5. 23 myorigin = $mydomain #发件人DNS后缀
  6. 24 mydestination = $mydomain #指定Postfix允许处理的邮件
  7. 25 home_mailbox = Maildir/ #邮箱类型
  8. 26 mynetworks = 172.16.1.0/24 #设置允许哪些客户端直接将需要 转发到外部区域的邮件提交给Postfix
[root@mail postfix]# postfix check  #检查配置文件语法是否有问题,经测试配置文件内不能有汉字,即使是注释。所以不要直接复制哦,不然服务无法启动的。

RHEL5中默认是启用了sendmail的,可以使用下面的命令查看是否有sendmail的进程。

[root@mail postfix]# netstat -tulnp | grep :25 #查看是否有sendmail的进程在监听25端口,无则直接跳过。
[root@mail postfix]# service sendmail stop  #有则禁用sendmail
[root@mail postfix]# chkconfig sendmail off

启用postfix

[root@mail postfix]# service postfix start
启动 postfix:                                             [确定]
[root@mail postfix]# chkconfig postfix on
[root@mail postfix]# netstat -tulnp | grep :25    #查看服务是否成功启动
tcp        0      0 0.0.0.0:25                  0.0.0.0:*                      LISTEN      4863/master  

配置收件服务

安装dovecot,这个软件包提供了POP3的收件服务

[root@mail ~]# vim /etc/dovecot.conf 
  1. ...
  2. 211 mail_location = maildir:~/Maildir #去掉行首注释,并添加你设置的邮件存储目录
  3. ...
[root@mail ~]# service dovecot start
启动 Dovecot Imap:                                        [确定]
[root@mail ~]# chkconfig dovecot on
[root@mail ~]# netstat -tulnp | grep  dovecot
tcp        0      0 :::993                      :::*                        LISTEN      10998/dovecot     #用于imap加密连接 
tcp        0      0 :::995                      :::*                        LISTEN      10998/dovecot     #用于POP3加密连接 
tcp        0      0 :::110                      :::*                        LISTEN      10998/dovecot     #用于POP3非加密连接
tcp        0      0 :::143                      :::*                        LISTEN      10998/dovecot     #用于imap非加密连接

测试

可以使用telnet在命令行下测试,也可以使用Thunderbird、foxmail等客户端进行测试:
我新建了两个用户test_se和test_re用于测试发信和收信
telnet发信:
[root@dns1 named]# telnet mail.test.com 25  
Trying 172.16.1.253...  
Connected to mail.test.com (172.16.1.253).  
Escape character is '^]'.  
220 mail.test.com ESMTP Postfix  
helo  
501 Syntax: HELO hostname  
mail from:test_se@test.com  
250 2.1.0 Ok  
rcpt to:test_re@test.com  
250 2.1.5 Ok  
data  
354 End data with .  
This is a test mail!!  
.  
250 2.0.0 Ok: queued as 7A38A2177E0  
quit  
221 2.0.0 Bye  
Connection closed by foreign host.

telnet收信:
[root@mail ~]# telnet 172.16.1.253 110  
Trying 172.16.1.253...  
Connected to 172.16.1.253 (172.16.1.253).  
Escape character is '^]'.  
+OK Dovecot ready.  
user test_re  
+OK  
pass test  
+OK Logged in.  
list  
+OK 1 messages:  
1 445  
.  
retr 1  
+OK 445 octets  
Return-Path:   
X-Original-To: test_re@test.com  
Delivered-To: test_re@test.com  
Received: from unknown (unknown [172.16.1.254])  
    by mail.test.com (Postfix) with SMTP id 7A38A2177E0  
    for ; Sun, 27 Apr 2014 10:16:20 +0800 (CST)  
Message-Id: <20140427021639.7A38A2177E0@mail.test.com>  
Date: Sun, 27 Apr 2014 10:16:20 +0800 (CST)  
From: test_se@test.com  
To: undisclosed-recipients:;  
                                                  .  
This is a test mail!!  
.  
quit  
+OK Logging out.  
Connection closed by foreign host.

thunderbird测试:

发信测试

收信测试

搭建webmail管理平台

这里使用的是squirrelmail,先安装:

[root@mail ~]# yum install -y squirrelmail

配置squirrelmail

[root@mail ~]# vim /etc/squirrelmail/config.php 
  1. ...
  2. 26 $squirrelmail_default_language = 'zh_CN'; #更改为中文
  3. 27
  4. 28 $domain = 'test.com'; #修改为你的域
  5. 29 $imapServerAddress = '172.16.1.253';#mail服务器的IP
  6. ...
  7. 32 $smtpServerAddress = '172.16.1.253';
  8. ...

启动httpd服务:
[root@mail ~]# service httpd start
[root@mail ~]# chkconfig httpd on
打开测试页面查看效果:
登录

管理

根据客户端地址对客户端进行过滤

增加希望限制的IP:

[root@mail ~]# vim /etc/postfix/access 
  1. ...
  2. 416 172.16.1.254 REJECT
  3. 417 172.16.1.1 OK

生产数据库文件,使postfix可以识别:

[root@mail ~]# postmap /etc/postfix/access

编辑主配置文件,增加如下内容:

[root@mail ~]# vim /etc/postfix/main.cf    
  1. ...
  2. 28 smtpd_client_restrictions = check_client_access hash:/etc/postfix/access
  3. ...
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注