天天看點

Sendmail服務全攻略之進階配置

sendmail.cf是Sendmail的配置檔案,它全權決定了Sendmail的屬性。這個檔案定義郵件伺服器為哪個域工作。其中的内容為特定宏,大多數人對它都抱有恐懼心理,因為檔案中的宏代碼實在是太多。sendmail.cf通常是由一個以mc結尾的檔案編譯産生。如Redhat自帶一個redhat.mc,使用者可以自己修改其中的一些設定,使之适合自己。筆者的sendmail.mc 檔案内容如下: 

divert(-1) 
dnl This is the macro config file used to generate the /etc/sendmail.cf 
dnl file. If you modify thei file you will have to regenerate the 
dnl /etc/sendmail.cf by running this macro config through the m4 
dnl preprocessor: 
dnl m4 /etc/sendmail.mc > /etc/sendmail.cf 
dnl You will need to have the Sendmail-cf package installed for this to work. 
include(`/usr/lib/Sendmail-cf/m4/cf.m4') 
define(`confDEF_USER_ID',``8:12'') 
OSTYPE(`Linux') 
undefine(`UUCP_RELAY') 
undefine(`BITNET_RELAY') 
define(`confAUTO_REBUILD') 
define(`confTO_CONNECT', `1m') 
define(`confTRY_NULL_MX_LIST',true) 
define(`confDONT_PROBE_INTERFACES',true) 
define(`PROCMAIL_MAILER_PATH',`/usr/bin/procmail') 
FEATURE(`smrsh',`/usr/sbin/smrsh') 
FEATURE(`mailertable',`hash -o /etc/mail/mailertable') 
FEATURE(`virtusertable',`hash -o /etc/mail/virtusertable') 
FEATURE(redirect) 
FEATURE(always_add_domain) 
FEATURE(use_cw_file) 
FEATURE(local_procmail) 
MAILER(smtp) 
MAILER(procmail) 
FEATURE(`access_db') 
FEATURE(`blacklist_recipients') 
dnl We strongly recommend to comment this one out if you want to protect 
dnl yourself from spam. However, the laptop and users on computers that do 
dnl not hav 24x7 DNS do need this. 
FEATURE(`accept_unresolvable_domains') 
dnl FEATURE(`relay_based_on_MX') 

編譯sendmail.mc以産生需要的sendmail.cf檔案:# m4 /etc/sendmail.mc > /etc/mail/sendmail.cf。 

生成sendmail.cf以後,編輯sendmail.cf。在檔案中,查找DS,在其後加入郵件伺服器名、域名,這樣可以保證當你以[email protected]或[email protected]發信時,使用者都可以收到,如下所示: 

# Alias for this host 
Cw mail.domain.com domain.com 

然後,就可以啟動Sendmail了:# /usr/sbin/Sendmail -bd -q20m。 

Sendmail 8.9.x以後的版本,在預設情況下,都預設不對未驗證的計算機進行轉發(Relay),是以如果要為本機以外的其他計算機進行郵件轉發,這時,應該在相應的配置檔案中明确告訴Sendmail要對哪幾個主機進行轉發。如果不考慮驗證,對任何主機都進行轉發的話,可以在sedmail.mc檔案中加入一行:FEATURE(promiscuous_relay)。 

不過,如果你的計算機是放在公網上的話,建議你不要這樣做,因為這樣做了以後,任何人都可以使用你的計算機進行轉發郵件了,特别是一些别有用心的人或一些兜售客(spammer,垃圾郵件制造者)會利用你的郵件伺服器的轉發功能亂發大量的垃圾郵件。 

使用說明 
通常情況下,Sendmail不會為郵件服務Relay資訊,這樣可以防止一些有惡意的人利用别人的郵件伺服器亂發郵件。預設情況下,Sendmail關閉了Relay功能。如果你要為别的伺服器Relay郵件,可以進行如下設定——在access檔案中加入要為其Relay信件的機器,格式為: 

hostname RELAY 
ipaddress RELAY 

如果要為一個域内多個機器Relay信件,則可以在/etc/mail/access檔案中直接加入其子網IP或域名,如下所示: 

access檔案内容: 
domainname.com RELAY(允許為域domainname的所有計算機relay郵件) 
localhost RELAY 
192.168.1.0 RELAY (為192.168.1.0此網内所有機器relay郵件) 

此檔案惟一決定了哪些機器、哪個域可以使用郵件伺服器轉發郵件。完成後需要進行編譯:#makemap hash access.db < access。 

其他配置的檔案關系不是很大,可以暫時使用預設安裝的内容。至此,Sendmail應該可以正常工作了。 

接下來是測試郵件伺服器的郵件發送功能,注意:測試時,不要隻對本地使用者進行測試,如:你的域為abc.com,測試時,不要隻在郵件伺服器上測試[email protected]使用者。因為,此時user1是本地使用者,是以郵件伺服器可以對其進行Relay。你應該從區域網路上的另一台機器使用Outlook等郵件用戶端對伺服器進行測試。