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配置編譯sendmail.mc以產生需要的sendmail.cf檔案:# m4 /etc/sendmail.mc > /etc/mail/sendmail.cf。
產生sendmail.cf以後,編輯sendmail.cf。在檔案中,尋找DS,在其後加入郵件伺服器名、網域名稱,這樣可以保證當你以username@mail.domain.com或username@domain.com發信時,使用者都可以收到,如下所示:
# 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,垃圾郵件製造者)會利用你的郵件伺服器的轉寄功能亂髮大量的垃圾郵件。