postfix搭建純郵件轉寄伺服器 1)安裝dns aptitude install bind9 dnsutils 2) 配置dns a) named.conf.local zone "test.com"{ type master; file "/etc/bind/test.com"; }; b) dgnc.om $TTL 604800 @ IN SOA @ mail203.local.( 20130305 604800 86400 2419200 604800) @ IN NS 192.168.1.203. MX 0 mail203 mail203 IN A 192.168.1.203 mail202 IN A 192.168.1.202 3) 配置postfix a) /etc/postfix/main.cf mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 192.168.1.202 <<============192.168.1.202設定可通過postfix發送郵件的用戶端IP或IP段 relay_domains = test.com <<================設定postfix可幫忙轉寄哪些向內發送的郵件,此處表示postfix可轉寄外部網路發給test.com網域郵箱的郵件 transport_maps = hash:/etc/postfix/transport <<=================設定postfix轉寄某網域郵件(如:test.com)的目的地檔案 b) 建立/etc/postfix/transport檔案 內容: test.com relay:[mail202.test.com] <<=====================mail202.test.com表示postfix轉寄郵件給內部網路的SMTP伺服器所在主機名稱 c) 產生transport對應資料庫檔案transport.db 命令: postmap /etc/postfix/transport 4) 垃圾郵件過濾 根據如上設定,postfix可接收並轉寄test.com網域的所有郵件,但postfix並不知道test.com網域有哪些收件者,這樣就會導致postfix收下許多無效的test.com網域郵件,最終無法轉寄而積壓,最終導致postfix崩潰 解決辦法:將test.com網域的所有有效郵箱同步到postfix,以便postfix能及時判斷收到test.com網域郵件的有效性 a) 修改/etc/postfix/main.cf 添加:relay_recipient_maps = hash:/etc/postfix/relay_recipients b) 建立/etc/postfix/relay_recipients # touch /etc/postfix/relay_recipients 檔案內容: admin@test.com OK 說明:admin@test.com: 表示test.com網域的有效郵箱 OK:此處可以是任一字元串,因檔案格式的需要,必須填寫 5) 測試: a) 外發郵件: 根據上面mynetworks設定,postfix只能轉寄postfix所在主機或192.168.1.202主機的郵件,現在假設登入postfix所在主機,粗體部分是需要我們手動輸入的內容 測試步驟如下: telnet localhost 25 Trying 192.168.1.202... Connected to 192.168.1.202 (192.168.1.202). Escape character is '^]'. 220 localhost.localdomain ESMTP Postfix helo test.com 250 localhost.localdomain mail from:<test@test.com> 250 2.1.0 Ok rcpt to:<zzban@126.com> 250 2.1.5 Ok data 354 End data with <CR><LF>.<CR><LF> Subject: this is a test mail This is test mail content . (注意此處的點".",表示郵件內容的結束標記) 250 2.0.0 Ok: queued as 88B3B2A68032 quit 221 2.0.0 Bye Connection closed by foreign host. 這樣郵件就發送出去了,你可以登入你的收件郵件看看有沒有收到郵件。如果收到郵件,表示一切正常,結束。 b) 內發郵件 步驟同上,只需將mail from所示的寄件者和rcpt to所示的收件者郵箱互換即可 6) 發現問題 如在測試過程中發現測試不成功 ,不能正常收到郵件,或者是測試過程中,你想查看整個測試過程,你可以查看postfix的發送或內送郵件的log資訊 log所在位置:/var/log/mail.info或/var/log/mail.log