邮件传输过程中主要有MTA,MUA,MAA,MDA
MUA:邮件用户代理(Mail User Agent),指的是客户端程序,如outlook,foxmail,thunderbird
MTA:邮件传输代理(Mail Transfer Agent),指dovecot软件提供的pop3,imap等收信服务
MDA:邮件过滤代理(Mail Delivery Agent),主要有procmail等
Sendmail常规服务器配置流程:
(1)配置sendmail.mc文件
(2)使用m4工具将sendmail.mc文件导入sendmail.cf文件
(3)配置local-host-names文件
(4)建立用户帐号
(5)重新启动服务使配置生效
在配置sendmail之前,需要设置并搭建DNS服务器。
[root@localhost /]# nslookup
> set type=mx
> gd2010.com.
Server: 172.26.39.23
Address: 172.26.39.23#53
gd2010.com mail exchanger = 10 mail.gd2010.com.
实验目的:实现域内发送/接收邮件
RHEL5默认安装sendmail-8.13.8-2.el5及m4-1.4.5-3.el5.1,只需要安装sendmail-cf-8.13.8-2.el5宏文件包
[root@localhost Server]# rpm -ivh sendmail-cf-8.13.8-2.el5.i386.rpm #安装sendmail-cf包,提供主要的模板
1)修改 /etc/mail/sendmail.mc第116行将smtp侦听范围从127.0.0.1改为0.0.0.0,否则邮件服务器无法正常发送邮件
#出于安全考虑,默认只对lo回环网络接口(IP地址为127.0.0.1)提供服务,为了使服务器能够为主机的所有网络接口(地址为0.0.0.0)提供服务,开启sendmail服务器的网络接口
2)修改第155行修改成域名:LOCAL_DOMAIN(`gd2010.com')dnl
3)使用m4宏生成半二进制的配置文件 m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
4)修改/etc/mail/local-host-names 文件添加域名和主机名
[root@localhost Server]# cat >>/etc/mail/local-host-names<<EOF
> gd2010.com.
> mail.gd2010.com.
> EOF
5)如果需要使用POP3和IMAP协议接收邮件需要安装dovecot软件包
安装dovecot软件包要解决其依赖性
[root@localhost Server]# rpm -ivh perl-DBI-1.52-1.fc6.i386.rpm
[root@localhost Server]# rpm -ivh mysql-5.0.22-2.1.i386.rpm
[root@localhost Server]# rpm -ivh postgresql-libs-8.1.11-1.el5_1.1.i386.rpm # 解决libpq.so.4
[root@localhost Server]# rpm -ivh dovecot-1.0-1.2.rc15.el5.i386.rpm
===========================================================================
可以架设YUM本地服务器实现解决依赖性自动化安装
[root@localhost ~]# mkdir -p /media/yum
[root@localhost ~]# mount /dev/cdrom /media/yum/
mount: block device /dev/cdrom is write-protected, mounting read-only
[root@localhost ~]# cd /media/yum/Server/
[root@localhost Server]# rpm -ivh createrepo-0.4.4-2.fc6.noarch.rpm
[root@localhost Server]# cd /media/
[root@localhost media]# createrepo .
[root@localhost media]# cat >/etc/yum.repos.d/server.repo<<EOF
> [yum]
> baseurl=file:///media
> enabled=1
> EOF
===========================================================================
[root@localhost Server]# /etc/init.d/sendmail restart
[root@localhost Server]# /etc/init.d/dovecot restart
[root@localhost Server]# netstat –ntla #使用netstat命令测试是否开启SMTP的25端口、POP3的110端口及IMAP的143端口
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:795 0.0.0.0:* LISTEN
tcp 0 0 :::993 :::* LISTEN
tcp 0 0 :::995 :::* LISTEN
tcp 0 0 :::110 :::* LISTEN
tcp 0 0 :::143 :::* LISTEN
tcp 0 0 :::22 :::* LISTEN
[root@localhost Server]# telnet localhost 25 #验证Sendmail的SMTP认证功能
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 localhost.localdomain ESMTP Sendmail 8.13.8/8.13.8; Thu, 2 Sep 2010 21:09:54 -0700
ehlo localhost #验证Sendmail的SMTP认证功能
250-localhost.localdomain Hello localhost.localdomain [127.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-DELIVERBY
250 HELP
quit
221 2.0.0 localhost.localdomain closing connection
Connection closed by foreign host.
===========================================================================
[root@localhost Server]# telnet localhost 110
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
+OK Dovecot ready.
===========================================================================
创建用户账号
注:sendmail服务器使用linux系统中的用户账号作为邮件账号,因此为用户添加邮件账号只需要添加linux用户账号即可。为了便于对邮件用户进行管理,由于邮件账号通常不需要登录linux系统,因此可以在adduser命令使用“-s”选项指定用户的shell为“/sbin/nologin”,即不允许用户登录linux系统。在建立邮件用户账号之后,需要使用passwd命令为用户设置口令,以便用户发送和收取邮件时进行身份认证。
[root@localhost Server]# useradd user1
[root@localhost Server]# useradd user2
[root@localhost Server]# su user1
[user1@localhost Server]$ mail -vs "what is the weather like today?" user2@gd2010.com
do you know ? i love you
.
Cc:
user2@gd2010.com... Connecting to [127.0.0.1] via relay...
220 localhost.localdomain ESMTP Sendmail 8.13.8/8.13.8; Fri, 3 Sep 2010 05:32:24 -0700
>>> EHLO localhost.localdomain
250-localhost.localdomain Hello localhost.localdomain [127.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-DELIVERBY
250 HELP
>>> MAIL From:<user1@localhost.localdomain> SIZE=103
250 2.1.0 <user1@localhost.localdomain>... Sender ok
>>> RCPT To:<user2@gd2010.com>
>>> DATA
250 2.1.5 <user2@gd2010.com>... Recipient ok
354 Enter mail, end with "." on a line by itself
>>> .
250 2.0.0 o83CWOAA010249 Message accepted for delivery
user2@gd2010.com... Sent (o83CWOAA010249 Message accepted for delivery)
Closing connection to [127.0.0.1]
>>> QUIT
221 2.0.0 localhost.localdomain closing connection
===========================================================================
[user1@localhost Server]$ su user2
Password:
[user2@localhost Server]$ cat /var/spool/mail/user2
From user1@localhost.localdomain Fri Sep 3 05:32:24 2010
Return-Path: <user1@localhost.localdomain>
Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
by localhost.localdomain (8.13.8/8.13.8) with ESMTP id o83CWOAA010249
for <user2@gd2010.com>; Fri, 3 Sep 2010 05:32:24 -0700
Received: (from user1@localhost)
by localhost.localdomain (8.13.8/8.13.8/Submit) id o83CWONV010248
for user2@gd2010.com; Fri, 3 Sep 2010 05:32:24 -0700
Date: Fri, 3 Sep 2010 05:32:24 -0700
From: user1@localhost.localdomain
Message-Id: <201009031232.o83CWONV010248@localhost.localdomain>
To: user2@gd2010.com
Subject: what is the weather like today?
do you know ? i love you
===========================================================================
[root@localhost Server]# cat /var/log/maillog
#所有信息都存储在这个日志文件中,包括用户名,主机名,出错代码。这些出错代码很有用处,可以通过这些让你对自己有更好的了解
Sep 3 05:32:24 localhost sendmail[10248]: o83CWONV010248: from=user1, size=103, class=0, nrcpts=1, msgid=<201009031232.o83CWONV010248@localhost.localdomain>, relay=user1@localhost
Sep 3 05:32:24 localhost sendmail[10249]: o83CWOAA010249: from=<user1@localhost.localdomain>, size=392, class=0, nrcpts=1, msgid=<201009031232.o83CWONV010248@localhost.localdomain>, proto=ESMTP, daemon=MTA, relay=localhost.localdomain [127.0.0.1]
Sep 3 05:32:24 localhost sendmail[10248]: o83CWONV010248: to=user2@gd2010.com, ctladdr=user1 (501/501), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30103, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (o83CWOAA010249 Message accepted for delivery)
Sep 3 05:32:24 localhost sendmail[10250]: o83CWOAA010249: to=<user2@gd2010.com>, ctladdr=<user1@localhost.localdomain> (501/501), delay=00:00:00, xdelay=00:00:00, mailer=local, pri=30602, dsn=2.0.0, stat=Sent