注册 | 登录 忘记密码? 51cto首页 | 博客 | 论坛 | 招聘
热点文章 IB客座主编(四)美国西蒙公..
 帮助

CentOS4.4下邮件服务器架设笔记之邮件网关功能实现


2007-09-30 16:51:17
版权声明:原创作品,谢绝转载!否则将追究法律责任。
1.通过参考以上两篇文章:
        我们基本上实现了邮件收发,以及对垃圾邮件过滤的功能,但是目前面对企业来说,用microsoft exchange的比较多,我的想法,就是想要把这台邮件服务器的变成邮件网关,所有流进内部邮件服务器的邮件先经过MX GATEWAY扫描后,再往后面丢;虽然目前市面上很多这样功能的产品,但是价格却是一笔投资,但是LINUX却能容易做到;我在此写BLOG,把自己测试的情况与大家交流,相信对初学者是一个总结;
        包括此篇文章的总结,也是花费我了将近一个月的时间抽空测试总结出来的,我希望以此作为抛砖引玉的功能,让大家把自己更好的总结给贡献出来!我自己是一个LINUX初学者,我想通过此平台认识更多的朋友,大家互相交流一下! QQ:418027712
 
2.转入正题:
首先介绍下我的内网测试环境:
a.参考上面两篇文档:分别架设服务器A,其IP地址:10.6.6.111;
b.新安装一台邮件服务器B,只包含(postfix+dovecot),没有垃圾过滤功能;来替代现实环境的exchange服务器,因为安装linux邮件服务器比microsoft平台的exchange快,简单,更重要的,找个古董机器都能装;
c.两台机器都是同一个域,centos.eb.cn
A机器名:mail.centos.eb.cn         B机器名:mail1.cenots.eb.cn
http://blog.51cto.com/attachment/200709/200709301191138323937.jpg" border="0" />
3.开始配置:
a.配置邮件网关机器A,修改通过传输表实现转发;
即当邮件发给A机器时,A全部转发给B机器;
[root@mail ~]# cd /etc/postfix
[root@mail postfix]# vi main.cf
增加
transport_maps = hash:/etc/postfix/transport
然后保存退出,并编辑:
[root@mail postfix]# vi transport
增加
centos.eb.cn  relay:[10.6.6.120]
保存退出后,执行:
[root@mail postfix]# postmap /etc/postfix/transport
[root@mail postfix]# postfix reload
postfix/postfix-script: refreshing the Postfix mail system
b.配置MailScanner.conf实现,当A机器对收到的外部邮件判断垃圾邮件时,丢到B机器的指定帐户spam@centos.eb.cn;
[root@mail postfix]# vi /etc/MailScanner/MailScanner.conf
#Spam Actions = deliver header "X-Spam-Status: Yes"      #将此行的配置注释掉;
Spam Actions = forward
spam@centos.eb.cn    #转发指定账户配置
#High Scoring Spam Actions = deliver header "X-Spam-Status: Yes"   #将此行的配置注释掉;
High Scoring Spam Actions = forward spam@centos.eb.cn  #转发指定账户配置
 
重新启动一下MailScanner
[root@mail postfix]# service MailScanner restart
Shutting down MailScanner daemons:
         MailScanner:                                      [  OK  ]
         incoming postfix:                                 [  OK  ]
         outgoing postfix:                                 [  OK  ]
Waiting for MailScanner to die gracefully ....................................................................... dead.
Starting MailScanner daemons:
         incoming postfix:                                 [  OK  ]
         outgoing postfix:                                 [  OK  ]
         MailScanner:                                      [  OK  ]
[root@mail postfix]#
其实MailScanner在判定为垃圾邮件处理有多种方式,见如下参数;
# This is just like the "Spam Actions" option above, except that it applies
# to messages that are *NOT* spam.
#    deliver                 - deliver the message as normal
#    delete                  - delete the message
#    store                   - store the message in the (non-spam) quarantine
#    store-nonmcp            - store the message in the non-MCP quarantine
#    store-mcp               - store the message in the MCP quarantine
#    store-nonspam           - store the message in the non-spam quarantine
#    store-spam              - store the message in the spam quarantine
#    forward
user@domain.com - forward a copy of the message to user@domain.com
#    striphtml               - convert all in-line HTML content to plain text
#    header "name: value"    - Add the header
#                                name: value
#                              to the message. name must not contain any spaces.
#    custom(parameter)       - Call the CustomAction function in /usr/lib/Mail-
#                              Scanner/MailScanner/CustomFunctions/CustomAction
#                              .pm with the 'parameter' passed in. This can be
#                              used to implement any custom action you require.
新建一个账户,收集垃圾邮件;
[root@mail postfix]# ssh root@10.6.6.120
mailto:root@10.6.6.120 password:
[root@mail1 ~]# adduser spam -s /sbin/nologin
Changing password for user spam.
New UNIX password:
BAD PASSWORD: it is too short
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
 
 
4.开始测试,分别发送一正常与垃圾信给leeki.yan@centos.eb.cn
a.首先从leeki.yan@trinet.com.cn测试一封正常信到leeki.yan@centos.eb.cn,理论上正常信,经过A机器扫描后,会往后面B机器relay,并且寄给leeki.yan@centos.eb.cn,查看日志如下:
Sep 30 16:38:36 mail postfix/smtpd[8637]: connect from unknown[10.0.0.1]
Sep 30 16:38:36 mail postfix/smtpd[8637]: 8002B170301: client=unknown[10.0.0.1]
Sep 30 16:38:36 mail postfix/cleanup[8639]: 8002B170301: hold: header Received: from mail.trinet.com.cn (unknown [10.0.0.1])??by mail.centos.eb.cn (Postfix) with ESMTP id 8002B170301??for <leeki.yan@centos.eb.cn>; Sun, 30 Sep 2007 16:38:36 +0800 (CST) from unknown[10.0.0.1]; from=<leeki.yan@trinet.com.cn> to=<leeki.yan@centos.eb.cn> proto=ESMTP helo=<mail.trinet.com.cn>
Sep 30 16:38:36 mail postfix/cleanup[8639]: 8002B170301: hold: header Received: from triumphweihu ([10.0.0.1]) by mail.trinet.com.cn with Microsoft SMTPSVC(5.0.2195.6713);?? Sun, 30 Sep 2007 16:47:36 +0800 from unknown[10.0.0.1]; from=<leeki.yan@trinet.com.cn> to=<leeki.yan@centos.eb.cn> proto=ESMTP helo=<mail.trinet.com.cn>
Sep 30 16:38:36 mail postfix/cleanup[8639]: 8002B170301: message-id=<00da01c8033d$5e55aa60$de04040a@triumphweihu>
Sep 30 16:38:36 mail postfix/smtpd[8637]: disconnect from unknown[10.0.0.1]
Sep 30 16:38:38 mail MailScanner[8125]: New Batch: Scanning 1 messages, 2650 bytes
Sep 30 16:38:42 mail MailScanner[8125]: Virus and Content Scanning: Starting
Sep 30 16:38:53 mail MailScanner[8125]: Requeue: 8002B170301.BC8D5 to 52652170302
Sep 30 16:38:53 mail MailScanner[8125]: Uninfected: Delivered 1 messages
Sep 30 16:38:53 mail postfix/qmgr[8107]: 52652170302: from=<leeki.yan@trinet.com.cn>, size=2872, nrcpt=1 (queue active)
Sep 30 16:38:53 mail postfix/smtp[8647]: 52652170302: to=<leeki.yan@centos.eb.cn>, relay=10.6.6.120[10.6.6.120], delay=17, status=sent (250 Ok: queued as 122AF2206E0)
Sep 30 16:38:53 mail postfix/qmgr[8107]: 52652170302: removed
 
见上面红色字体部分,说明已经往后B机器relay成功了!
 
b.从418027712@qq.com测试一封垃圾信到leeki.yan@centos.eb.cn,理论上垃圾信,经过A机器扫描后,会往后面B机器relay,寄给spam@centos.eb.cn,查看日志如下:
Sep 30 17:05:01 mail postfix/smtpd[3496]: connect from smtpbg12.qq.com[58.60.13.110]
Sep 30 17:05:01 mail postfix/smtpd[3496]: C9D89170301: client=smtpbg12.qq.com[58.60.13.110]
Sep 30 17:05:01 mail postfix/cleanup[3504]: C9D89170301: hold: header Received: from smtpbg12.qq.com (smtpbg12.qq.com [58.60.13.110])??by mail.centos.eb.cn (Postfix) with ESMTP id C9D89170301??for <leeki.yan@centos.eb.cn>; Sun, 30 Sep 2007 17:05:01 +0800 (CST) from smtpbg12.qq.com[58.60.13.110]; from=<418027712@qq.com> to=<leeki.yan@centos.eb.cn> proto=ESMTP helo=<smtpbg12.qq.com>
Sep 30 17:05:01 mail postfix/cleanup[3504]: C9D89170301: message-id=<tencent_46D546001FA9FA1C63F8C299@qq.com>
Sep 30 17:05:01 mail postfix/smtpd[3496]: disconnect from smtpbg12.qq.com[58.60.13.110]
Sep 30 17:05:02 mail MailScanner[3341]: New Batch: Scanning 1 messages, 1614 bytes
Sep 30 17:05:36 mail MailScanner[3341]: Spam Checks: Found 1 spam messages
Sep 30 17:05:36 mail MailScanner[3341]: Virus and Content Scanning: Starting
Sep 30 17:06:20 mail MailScanner[3341]: Requeue: C9D89170301.4D561 to 1B757170304
Sep 30 17:06:20 mail MailScanner[3026]: Uninfected: Delivered 1 messages
Sep 30 17:06:20 mail postfix/qmgr[2587]: 1B757170304: from=<418027712@qq.com>, size=1834, nrcpt=1 (queue active)
Sep 30 17:06:30 mail postfix/smtp[3591]: 1B757170304: to=<spam@centos.eb.cn>, relay=10.6.6.120[10.6.6.120], delay=89, status=sent (250 Ok: queued as 19B222206E0)
Sep 30 17:06:30 mail postfix/qmgr[2587]: 1B757170304: removed
由面日志红色字体部分可以看出,首先检测发现邮件为垃圾邮件,然后,在往B机器relay时,投寄到spam@centos.eb.cn;
 
5.测试完成!
 
 
6.2007年10月8日22时补充说明:
,但是经与jacky网友聊天得知:理论上,邮件网关配置好了后,外部发过的来的邮件到邮件网关时,是不需要查询本地用户组的,他只管往后面丢,所以我测试查找发现,要修改邮件网关的main.cf文件,找到:
#local_recipient_maps =
修改成:
local_recipient_maps = 
即把注释给取消掉,就可以!

本文出自 “成就梦想---唯有执著努力!” 博客,谢绝转载!





    文章评论
 
2007-10-12 11:13:45
又装一个服务器
貌似只实现网关哦
再全一些吧

2007-11-01 18:09:18
开花了告诉我~

2008-01-24 20:07:09
http://g.51cto.com/linux
推入博客圈!

 

发表评论

昵   称:
验证码:  点击图片可刷新验证码  博客过2级,无需填写验证码
内   容: