2009年7月15日星期三

sendmail 實驗

1. 設定sendmail 可以接收外部連線

修改 sendmail.mc

DAEMO_OPTIONS( `Port=smtp,Addr=0.0.0.0, Name=MTA')dnl

建立新的 sendmail.cf 設定檔

m4 sendmail.mc > sendmail.cf

測式:
[root@crim mail]# netstat -tln
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.1:2208 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:642 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
tcp 0 0 172.16.1.176:53 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:953 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN <--這裡有問題, tcp 0 0 127.0.0.1:2207 0.0.0.0:* LISTEN tcp 0 0 :::22 :::* LISTEN tcp 0 0 ::1:953 :::* LISTEN [root@crim mail]# telnet localhost 25 Trying 127.0.0.1... Connected to localhost.localdomain (127.0.0.1). Escape character is '^]'. 220 crim.localdomain ESMTP Sendmail 8.13.8/8.13.8; Tue, 14 Jul 2009 22:25:24 +0800 ^^^] telnet> exit
?Invalid command
telnet>
[root@crim init.d]# ./sendmail stop
Shutting down sm-client: [ OK ]
Shutting down sendmail: [ OK ]
[root@crim init.d]# ./sendmail start
Starting sendmail: [ OK ]
Starting sm-client: [ OK ]
[root@crim init.d]# netstat -tln
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.1:2208 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:642 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
tcp 0 0 172.16.1.176:53 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:53 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 127.0.0.1:953 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:2207 0.0.0.0:* LISTEN
tcp 0 0 :::22 :::* LISTEN
tcp 0 0 ::1:953 :::* LISTEN


[root@crim init.d]# telnet 172.16.1.176 25
Trying 172.16.1.176...
Connected to 172.16.1.176 (172.16.1.176).
Escape character is '^]'.
220 crim.localdomain ESMTP Sendmail 8.13.8/8.13.8; Tue, 14 Jul 2009 22:33:54 +0800

QUIT
Connection closed by foreign host.





[root@crim init.d]# cat /etc/mail/local-host-names
# local-host-names - include all aliases for your machine here.
openemm.testDomain.com


設定smtp認證

安裝 cyrus-sasl-md5 cyrus-sasl-plain cyrus-sasl 套件
[root@crim init.d]# yum install cyrus-sasl-md5 cyrus-sasl-plain cyrus-sasl
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp.cs.pu.edu.tw
* updates: ftp.cs.pu.edu.tw
* addons: ftp.cs.pu.edu.tw
* extras: ftp.cs.pu.edu.tw
Setting up Install Process
Parsing package install arguments
Package cyrus-sasl-plain-2.1.22-4.i386 already installed and latest version
Package cyrus-sasl-2.1.22-4.i386 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package cyrus-sasl-md5.i386 0:2.1.22-4 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
cyrus-sasl-md5 i386 2.1.22-4 base 45 k

Transaction Summary
================================================================================
Install 1 Package(s)
Update 0 Package(s)
Remove 0 Package(s)

Total download size: 45 k
Is this ok [y/N]: y
Downloading Packages:
cyrus-sasl-md5-2.1.22-4.i386.rpm | 45 kB 00:01
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : cyrus-sasl-md5 [1/1]

Installed: cyrus-sasl-md5.i386 0:2.1.22-4
Complete!
[root@crim init.d]# rpm -qa |grep cyrus
cyrus-sasl-plain-2.1.22-4
cyrus-sasl-lib-2.1.22-4
cyrus-sasl-2.1.22-4
cyrus-sasl-devel-2.1.22-4
cyrus-sasl-md5-2.1.22-4


修改之前的 /etc/mail/sendmail.mc

將下面兩行最前面的 dnl 拿掉
52 TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
53 define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl

重新產生sendmail.cf檔 : m4 sendmail.mc > sendmail.cf

重新啟動 sendmail 服務: service sendmail restart
[root@crim mail]# m4 sendmail.mc >sendmail.cf
[root@crim mail]# diff sendmail.cf sendmail.cf.change1
19c19
< ##### built by root@crim.localdomain on Tue Jul 14 22:46:16 HKT 2009 --- > ##### built by root@crim.localdomain on Tue Jul 14 22:23:52 HKT 2009
142d141
< authmechanisms="EXTERNAL"> #O AuthMechanisms=EXTERNAL GSSAPI KERBEROS_V4 DIGEST-MD5 CRAM-MD5
1238c1237
<> R$* $#error $@ 5.7.1 $: "550 Relaying denied"
[root@crim mail]#



[root@crim mail]# /etc/init.d/sendmail restart
Shutting down sm-client: [ OK ]
Shutting down sendmail: [ OK ]
Starting sendmail: [ OK ]
Starting sm-client: [ OK ]
[root@crim mail]#


利用telnet 測式smtp認證功能是否生效(要有出現 LOGIN PLAIN才算)


[root@crim mail]# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 crim.localdomain ESMTP Sendmail 8.13.8/8.13.8; Tue, 14 Jul 2009 22:48:00 +0800
ehlo localhost
250-crim.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-AUTH DIGEST-MD5 CRAM-MD5 LOGIN PLAIN
250-DELIVERBY
250 HELP

------------------------------------

[root@crim mail]# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 crim.localdomain ESMTP Sendmail 8.13.8/8.13.8; Tue, 14 Jul 2009 22:51:19 +0800
HELO cri.com.hk
250 crim.localdomain Hello localhost.localdomain [127.0.0.1], pleased to meet you
MAIL FROM:ivantest@openemm.testDomain.com
250 2.1.0 ivantest@openemm.testDomain.com... Sender ok
RCPT TO:ivanyao@xxx.com
250 2.1.5 ivanyao@xxx.com... Recipient ok
DATA
354 Enter mail, end with "." on a line by itself
From : ivantest@openemm.testDeomain.com
to : testOpenemmSendmail
Subject: testSendmail
This is a test mail
.
250 2.0.0 n6EEpJ0l006399 Message accepted for delivery
QUIT
221 2.0.0 crim.localdomain closing connection
Connection closed by foreign host.
[root@crim mail]#


用windows Live Mail可以收到了

ivantest@openemm.testDomain.com;
收件人:testOpenemmSendmail@crim.localdomain;
testSendmail <--這個是標題 This is a test mail <--內容

没有评论:

发表评论