配置SENDMAIL服务器:
[root@homeserver ~]# vim /etc/sysconfig/network //修改主机名(@后面的内容)
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=homeserver.home.net
NISDOMAIN=home
[root@homeserver ~]# vim /etc/hosts //添加主机IP解析记录
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
192.168.1.222 homeserver.home.net
安装相关RPM包:
[root@homeserver ~]# rpm -ivh /var/rhcepkg/Server/sendmail-cf-8.13.8-2.el5.i386.rpm
[root@homeserver ~]# rpm -ivh /var/rhcepkg/Server/sendmail-8.13.8-2.el5.i386.rpm
[root@homeserver ~]# rpm -ivh /var/rhcepkg/Server/cyrus-sasl-lib-2.1.22-4.i386.rpm
[root@homeserver ~]# rpm -ivh /var/rhcepkg/Server/cyrus-sasl-plain-2.1.22-4.i386.rpm
[root@homeserver ~]# rpm -ivh /var/rhcepkg/Server/cyrus-sasl-2.1.22-4.i386.rpm
[root@homeserver ~]# rpm -ivh /var/rhcepkg/Server/perl-DBI-1.52-1.fc6.i386.rpm
[root@homeserver ~]# rpm -ivh /var/rhcepkg/Server/mysql-5.0.45-7.el5.i386.rpm
[root@homeserver ~]# rpm -ivh /var/rhcepkg/Server/dovecot-1.0.7-2.el5.i386.rpm
[root@homeserver ~]# vim /etc/mail/sendmail.mc //修改SENDMAIL主配置文件
DAEMON_OPTIONS(`Port=smtp,Addr=0.0.0.0, Name=MTA')dnl
TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
[root@homeserver ~]# m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf //M4宏编译
[root@homeserver ~]# /usr/sbin/saslauthd -a shadow
[root@homeserver ~]# echo /usr/sbin/saslauthd -a shadow >> /etc/rc.local
[root@homeserver ~]# vim /etc/rc.local
[root@homeserver ~]# /etc/init.d/saslauthd restart
Stopping saslauthd: [ OK ]
Starting saslauthd: [ OK ]
[root@homeserver ~]# /etc/init.d/sendmail restart
Shutting down sm-client: [ OK ]
Shutting down sendmail: [ OK ]
Starting sendmail: [ OK ]
Starting sm-client: [ OK ]
[root@homeserver ~]# vim /etc/dovecot.conf //修改dovecot配置文件
protocols = pop3
[root@homeserver ~]# /etc/init.d/dovecot restart
Stopping Dovecot Imap: [FAILED]
Starting Dovecot Imap: [ OK ]
[root@homeserver ~]# chkconfig sendmail on //设定开机自启
[root@homeserver ~]# chkconfig dovecot on
[root@homeserver ~]# chkconfig saslauthd on
[root@homeserver ~]# netstat –tl //检查服务是否开启
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 *:768 *:* LISTEN
tcp 0 0 localhost.localdomain:2208 *:* LISTEN
tcp 0 0 *:nfs *:* LISTEN
tcp 0 0 *:708 *:* LISTEN
tcp 0 0 *:39720 *:* LISTEN
tcp 0 0 *:netbios-ssn *:* LISTEN
tcp 0 0 *:5900 *:* LISTEN
tcp 0 0 *:sunrpc *:* LISTEN
tcp 0 0 *:dec_dlm *:* LISTEN
tcp 0 0 *:ftp *:* LISTEN
tcp 0 0 *:918 *:* LISTEN
tcp 0 0 localhost.localdomain:ipp *:* LISTEN
tcp 0 0 *:smtp *:* LISTEN
tcp 0 0 *:microsoft-ds *:* LISTEN
tcp 0 0 localhost.localdomain:2207 *:* LISTEN
tcp 0 0 *:pop3 *:* LISTEN
tcp 0 0 *:http *:* LISTEN
tcp 0 0 *:ssh *:* LISTEN
[root@homeserver ~]# iptables -L –n //检查防火墙是否有阻止策略
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
[root@homeserver ~]# sendmail –d0 //查看sendmail所能识别的主机名
============ SYSTEM IDENTITY (after readcf) ============
(short domain name) $w = homeserver
(canonical domain name) $j = homeserver.home.net
(subdomain name) $m = home.net
(node name) $k = homeserver.home.net
=======================================================
Recipient names must be specified
[root@homeserver ~]# vim /etc/mail/local-host-names //添加邮件主机名(@后面的内容)
# local-host-names - include all aliases for your machine here.
homeserver.home.net
[root@homeserver ~]# telnet 192.168.1.222 25 //进行本地测试
Trying 192.168.1.222...
Connected to homeserver.home.net (192.168.1.222).
Escape character is '^]'.
220 homeserver.home.net ESMTP Sendmail 8.13.8/8.13.8; Mon, 5 Apr 2010 13:55:35 +0800
HELO homeserver.home.net //开始”握手”
250 homeserver.home.net Hello homeserver.home.net [192.168.1.222], pleased to meet you
MAIL From :
irini@homeserver.home.net
//发件人地址
250 2.1.0 irini@homeserver.home.net... Sender ok
RCPT To :
jessica@homeserver.home.net
//收件人地址
250 2.1.5 jessica@homeserver.home.net... Recipient ok
DATA //开始输入内容
354 Enter mail, end with "." on a line by itself
this is a test mail //邮件内容
. //”点号”表示结束
250 2.0.0 o355tZQ3008174 Message accepted for delivery
Quit //退出
221 2.0.0 homeserver.home.net closing connection
Connection closed by foreign host.
[root@homeserver ~]# mailq //查看当前邮件列队
/var/spool/mqueue is empty
Total requests: 0
[root@homeserver ~]# su – Jessica //切换到JESSICA家目录下
-bash-3.2$ mail //查看邮件内容
Mail version 8.1 6/6/93. Type ? for help.
"/var/spool/mail/jessica": 1 message 1 new
>N 1 irini@homeserver.hom Mon Apr 5 13:57 11/457
& 1
Message 1:
From irini@homeserver.home.net Mon Apr 5 13:57:51 2010
Date: Mon, 5 Apr 2010 13:55:35 +0800
From: irini@homeserver.home.net
this is a test mail //与之前的内容相符
& q
[root@homeserver ~]# mutt -f pop://frank@homeserver.home.net //POP远程邮件接收测试, frank@homeserver.home.net 为邮件发送地址
Password for
frank@homeserver.home.net
: XXXXXX
q:Quit d:Del u:Undel s:Save m:Mail r:Reply g:Group ?:Help
---Mutt: pop://frank@homeserver.home.net/ [Msgs:0]---(date/date)------------------------------(all)---
To:
feng9422@126.com
//邮件接收地址
Subject: check for this test
y:Send q:Abort t:To c:CC s:Subj a:Attach file d:Descrip ?:Help
From: root <root@homeserver.home.net>
To:
feng9422@126.com
Have u received this test? //写邮件内容
q:Quit d:Del u:Undel s:Save m:Mail r:Reply g:Group ?:Help
---Mutt: pop://frank@homeserver.home.net/ [Msgs:0]---(date/date)----------------------------------------------------------------(all)---
Mail sent.
邮件服务器优化:
1- 关闭邮件RELAY功能
[root@homeserver ~]# vim /etc/mail/access //只留本地RELAY
Connect:localhost.localdomain RELAY
Connect:localhost RELAY
Connect:127.0.0.1 RELAY
[root@homeserver ~]# makemap hash access.db > /etc/mail/access //修改后执行此命令
2- 设定帐号不可登录系统
#useradd test –s /sbin/nologin
3- 添加事实黑名单-RBL(realtime blackhole list),服务器在接受邮件时会先去RBL的服务器查询该邮件地址是否处于黑名单中.
[root@homeserver ~]# vim /etc/mail/sendmail.mc
FEATURE(`dnsbl',`relays.ordb.org',` ″Email blocked using ORDB.org - see <http://ORDB.org/lookup/﹖host=″$&{client_addr}″>″')
[root@homeserver ~]# m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf //M4宏编译
[root@homeserver ~]# /etc/init.d/sendmail restart
4- spamassassin 来防止垃圾邮件
[root@homeserver ~]# yum install spamassassinlain //yum安装,因为依赖的包太多了
[root@homeserver ~]# /etc/init.d/spamassassin restart
Stopping spamd: [FAILED]
Starting spamd: [ OK ]
[root@homeserver ~]# chkconfig spamassassin on
默认规则(已经很充足了)都在/usr/share/spamassassin/目录下以.cf结尾的文件
[root@homeserver ~]# vim /usr/share/spamassassin/local.cf //添加本地规则
whitelist_from_rcvd
irinilu@theetonhotel.com
//允许这个地址的EM
whitelist_from_rcvd @theetonhotel.com //允许这个域名的EM
#wget –N –P /usr/share.spamassassin/ www.ccert.edu.cn/spam/sa/Chinese_rules.cf //下载中文反垃圾规则,也可做成计划任务,定期下载更新
--18:02:25-- http://www.ccert.edu.cn/spam/sa/Chinese_rules.cf
Resolving www.ccert.edu.cn... 202.112.57.9
Connecting to www.ccert.edu.cn|202.112.57.9|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 55342 (54K) [text/plain]
Remote file is newer, retrieving.
--18:02:26-- http://www.ccert.edu.cn/spam/sa/Chinese_rules.cf
Connecting to www.ccert.edu.cn|202.112.57.9|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 55342 (54K) [text/plain]
Saving to: `/usr/share/spamassassin/Chinese_rules.cf'
100%[=======================================================>]55,342 61.1K/s in 0.9s
18:02:27 (61.1 KB/s) - `/usr/share/spamassassin/Chinese_rules.cf' saved [55342/55342]
转载于:https://blog.51cto.com/irinilu/292526