sendmail配置

tonykorn97發表於2008-10-21

一,安裝:
[root@station10 ~]# yum install -y sendmail*

[root@station10 ~]# rpm -aq | grep sendmail
sendmail-doc-8.13.8-2.el5
sendmail-cf-8.13.8-2.el5
sendmail-devel-8.13.8-2.el5
sendmail-8.13.8-2.el5
[root@station10 ~]#

[@more@]


二,sendmail進入的配置
1,修改 /etc/mail/sendmail.mc 檔案,讓監聽所有網路卡地址,在前面加上dnl # 即可:

[root@station10 mail]# vi sendmail.mc
dnl # DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl

2,修改 /etc/mail/local-host-names 檔案。
[root@station10 mail]# cat local-host-names
# local-host-names - include all aliases for your machine here.
station10.example.com
[root@station10 mail]#

3,重啟 sendmail

[root@station10 mail]# service sendmail restart
Shutting down sendmail: [FAILED]
Starting sendmail: [ OK ]
Starting sm-client: [ OK ]
[root@station10 mail]#

4,檢視監聽的埠:
[root@station10 ~]# netstat -tulpn | grep sendmail
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 1094/sendmail: acce
[root@station10 ~]#


5,測試
[root@station10 ~]# mail -v root
Subject: test mail
test.
.
Cc:
root... Connecting to [127.0.0.1] via relay...
220 station10.example.com ESMTP Sendmail 8.13.8/8.13.8; Tue, 21 Oct 2008 00:13:23 +0800
>>> EHLO station10.example.com
250-station10.example.com 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:<> SIZE=35
250 2.1.0 <>... Sender ok
>>> RCPT To:<>
>>> DATA
250 2.1.5 <>... Recipient ok
354 Enter mail, end with "." on a line by itself
>>> .
250 2.0.0 m9KGDNiO001110 Message accepted for delivery
root... Sent (m9KGDNiO001110 Message accepted for delivery)
Closing connection to [127.0.0.1]
>>> QUIT
221 2.0.0 station10.example.com closing connection
[root@station10 ~]#


三,sendmail 出去的配置
1,umcomment the following linex in /etc/mail/sendmail.mc

EXPOSED_USER(`root')dnl
FEATURE(masquerade_envelope)dnl
MASQUERADE_AS('station10.example.com')dnl
FEATURE(masquerade_entire_domain)dnl

2,測試
[root@station10 ~]# mail -v
Subject: test
from station10.example.com
.
Cc:
... Connecting to [127.0.0.1] via relay...
220 station10.example.com ESMTP Sendmail 8.13.8/8.13.8; Tue, 21 Oct 2008 00:43:26 +0800
>>> EHLO station10.example.com
250-station10.example.com 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:<> SIZE=73
250 2.1.0 <>... Sender ok
>>> RCPT To:<>
>>> DATA
250 2.1.5 <>... Recipient ok
354 Enter mail, end with "." on a line by itself
>>> .
250 2.0.0 m9KGhQAN001280 Message accepted for delivery
... Sent (m9KGhQAN001280 Message accepted for delivery)
Closing connection to [127.0.0.1]
>>> QUIT
221 2.0.0 station10.example.com closing connection
[root@station10 ~]#

3,在其他機器上接收郵件
[root@station12 ~]# mail
Mail version 8.1 6/6/93. Type ? for help.
"/var/spool/mail/root": 1 message 1 new
>N 1 Tue Oct 21 07:56 19/905 "test"
& 1
Message 1:
From Tue Oct 21 07:56:06 2008
Date: Tue, 21 Oct 2008 00:43:26 +0800
From: root <>
To:
Subject: test

from station10.example.com

& q
Saved 1 message in mbox
[root@station12 ~]#


四,進入的郵箱別名
1,本地別名配置:/etc/aliases
[root@station10 mail]# vi /etc/aliases
新增:
xxx: root

xxx這個名字可以是不存在的使用者,使用者名稱後面記得加:

2,執行newaliases讓配置生效。
[root@station10 ~]# newaliases
/etc/aliases: 77 aliases, longest 10 bytes, 772 bytes total
[root@station10 ~]#

3,測試
[root@station10 ~]# mail xxx
Subject: test inbound
send to xxx
.
Cc:
[root@station10 ~]# mail
Mail version 8.1 6/6/93. Type ? for help.
"/var/spool/mail/root": 1 message 1 new
>N 1 Tue Oct 21 00:51 16/659 "test inbound"
& 1
Message 1:
From Tue Oct 21 00:51:43 2008
Date: Tue, 21 Oct 2008 00:51:43 +0800
From: root <>
To:
Subject: test inbound

send to xxx

& q
Saved 1 message in mbox
[root@station10 ~]#


4,虛擬別名配置:
修改/etc/mail/virtusertable檔案,增加下面一行:

[root@station10 mail]# cat virtusertable

[root@station10 mail]#

5,重啟服務
[root@station10 mail]# service sendmail restart
Shutting down sm-client: [ OK ]
Shutting down sendmail: [ OK ]
Starting sendmail: [ OK ]
Starting sm-client: [ OK ]
[root@station10 mail]#


6,測試:
傳送到station10伺服器中:
[root@station10 mail]# mail
Subject: test inbound sendmail Aliases
send to station10
.
Cc:
[root@station10 mail]#

在station12伺服器中接收到資料:
Saved 1 message in mbox
[root@station12 ~]# mail
Mail version 8.1 6/6/93. Type ? for help.
"/var/spool/mail/root": 1 message 1 new
>N 1 Tue Oct 21 08:13 19/921 "test inbound sendmail"
& 1
Message 1:
From Tue Oct 21 08:13:36 2008
Date: Tue, 21 Oct 2008 01:00:56 +0800
From: root <>
To:
Subject: test inbound sendmail Aliases

send to station10

& q
Saved 1 message in mbox
[root@station12 ~]#


五,出去的地址重寫
1,在/etc/mail/sendmail.mc中增加如下內容:
FEATURE(genericstable)dnl
FEATURE(`always_add_domain')dnl
GENERICS_DOMAIN_FILE(`/etc/mail/local-host-names')dnl

例子,檔案最後幾行:
dnl MASQUERADE_DOMAIN(mydomain.lan)dnl
FEATURE(genericstable)dnl
FEATURE(`always_add_domain')dnl
GENERICS_DOMAIN_FILE(`/etc/mail/local-host-names')dnl
MAILER(smtp)dnl
MAILER(procmail)dnl
dnl MAILER(cyrusv2)dnl

2,新增檔案 /etc/mail/genericstable,並新增如下內容:
[root@station10 mail]# cat /etc/mail/genericstable


[root@station10 mail]#

3,重啟服務
[root@station10 mail]# /etc/init.d/sendmail restart
Shutting down sm-client: [ OK ]
Shutting down sendmail: [ OK ]
Starting sendmail: [ OK ]
Starting sm-client: [ OK ]
[root@station10 mail]#

4,測試:
傳送郵件給station12.example.com
[root@station10 ~]# mail
Subject: station10.example.com
test
.
Cc:
[root@station10 ~]#

查收接收到郵件:
[root@station12 ~]# mail
Mail version 8.1 6/6/93. Type ? for help.
"/var/spool/mail/root": 2 messages 2 new
>N 1 Tue Oct 21 11:14 69/2334 "Logwatch for station1"
N 2 Wed Oct 22 02:39 19/867 "station10.example.com"
& 2
Message 2:
From Wed Oct 22 02:39:53 2008
Date: Tue, 21 Oct 2008 19:26:56 +0800
From: root <>
To:
Subject: station10.example.com

test

& q
Saved 1 message in mbox
Held 1 message in /var/spool/mail/root
[root@station12 ~]#

六,垃圾郵件限制:
1,enable in /etc/mail/sendmail.mc using
FEATURE('blacklist_recipients')dnl

2, add restrictions in /etc/mail/access

From:90trialspammer@aol.com REJECT
Connect:spamRus.net REJECT
Connect:204.168.23 REJECT
Connect:10.3 OK
From:virtualdomain1.com RELAY
to:user@dom9.com ERROR:550 mail discarded
to:nobody@ ERROR:550 bad name

七,Sendmail Operation

mail -v user
view SMTP exchange with local relay

mailq and mailq -Ac
view messages queued for future delivery

sendmail -q
reprocess the email queue

tail -f /var/log/maillog
view log in real-time

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/312079/viewspace-1012207/,如需轉載,請註明出處,否則將追究法律責任。

相關文章