Linux下Postfix的配置和使用


Postfix為何物,詳見:http://zh.wikipedia.org/wiki/Postfix

0.關於Postfix

postfix的產生是為了替代傳統的sendmail.相較於sendmail,postfix在速度。性能和穩定性上都更勝一籌。如今眼下許多的主流郵件服務事實上都在採用postfix. 當我們須要一個輕量級的的郵件server是,postfix不失為一種選擇。

1. postfix是免費的:
    postfix想要作用的范圍是廣大的Internet用戶。試圖影響大多數的Internet上的電子郵件系統,因此它是免費的。
2. 更快:
    postfix在性能上大約比sendmail快三倍。一部執行postfix的台式PC每天能夠收發上百萬封郵件。
3. 兼容性好:
    postfix是sendmail兼容的,從而使sendmail用戶能夠非常方便地遷移到postfix。Postfix支持/var[/spool]/mail、/etc/aliases、 NIS、和 ~/.forward 文件。
   4. 更健壯:
postfix被設計成在重負荷之下仍然能夠正常工作。當系統執行超出了可用的內存或磁盤空間時,postfix會自己主動降低執行進程的數目。當處理的郵件數目增長時,postfix執行的進程不會跟着添加。
5. 更靈活:
postfix是由超過一打的小程序組成的,每一個程序完畢特定的功能。

你能夠
通過配置文件設置每一個程序的執行參數。


   6. 安全性
postfix具有多層防御結構,能夠有效地抵御惡意入侵者。如大多數的postfix程序能夠執行在較低的權限之下,不能夠通過網絡訪問安全性相關的本地投遞程序等等。

以下來介紹linux上怎樣搭建和配置postfix服務:


1.關掉sendmail相關的全部服務,最好是直接卸載sendmail.

# service sendmail stop
# chkconfig sendmail off

#rpm -qa | grep sendmail | xargs rpm -e


2.安裝postfix.

redhat6.0以上版本號應該是默認集成了postfix服務的,假如沒有安裝的話,能夠手動安裝。

rpm -qa | grep postifx (查看是否安裝)

yum install postfix


3.安裝完畢后。改動配置文件:/etc/postfix/main.cfg


vi /etc/postfix/main.cf


myhostname = sample.test.com  ← 設置系統的主機名


mydomain = test.com  ← 設置域名(我們將讓此處設置將成為E-mail地址“@”后面的部分)


myorigin = $mydomain  ← 將發信地址“@”后面的部分設置為域名(非系統主機名)


inet_interfaces = all  ← 接受來自全部網絡的請求


mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain  ← 指定發給本地郵件的域名


home_mailbox = Maildir/  ← 指定用戶郵箱文件夾


<保存退出。>


4.為本機加入DNS server.

為什DNS Server?由於在郵件發送過程中。須要把郵件地址的domain地址轉化成IP地址,再去發送給相應的收件人,這里涉及到DNS中的A記錄和MX記錄相關的知識,不熟悉的同學能夠google或者百度 腦補一下 :-)


怎樣加入DNS server呢,DNS server去哪里尋找?

vim /etc/resolv.conf 

加入例如以下行:

nameserver 8.8.8.8

nameserver 8.8.4.4


上面用的8.8.8.8/8.8.4.4是Google Free DNS server,當然還有非常多免費的DNS server供大家使用,能夠google一下:-)


5.測試一下郵件是否可以發送成功:

命令行輸入$: > echo "Mail Content" | mail -s "Mail Subject" xxxx@xxx.com

Note:if you see below warings after you run above command.

send-mail: warning: inet_protocols: IPv6 support is disabled: Address family not supported by protocol
send-mail: warning: inet_protocols: configuring for IPv4 support only
postdrop: warning: inet_protocols: IPv6 support is disabled: Address family not supported by protocol
postdrop: warning: inet_protocols: configuring for IPv4 support only

that means you don't have IPv6 configured in your OS's network stack, but your mailer (presumably postfix) is configured to use IPv6. Since there is no IPv6 for your mailer to use, it's warning you that it's only going to use IPv4.

 

To disable the waring messsage, go to /etc/postfix/main.cf and change from:

inet_protocols = all

to:

inet_protocols = ipv4

This will only use ipv4 and the warning message will go away.

You will have to issue a stop and start for postfix to register the change. 

service postfix restart


6.查看log,確認郵件發送狀態:

Postfix郵件的log位置是:/var/log/maillog

發送成功的話。會返回250和OK,也能夠去自己的郵件client查收。


一切OK的話,那Postfix mail service應該就搭建成功了。


&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

另外一些實用的postfix維護命令。一遍日常的檢測和維護:

mailq :會列出當前在postfix發送隊列中的全部郵件

postsuper -d ALL:刪除當前等待發送隊列的全部郵件,包含發送失敗的退信

當然還有非常多,就不一一列舉了,大家能夠網上搜索擴展。Good Luck!


7.Update Mail From sender

echo "do-not-reply@example.com   root@example.com" >> /etc/postfix/generic 
echo "smtp_generic_maps = hash:/etc/postfix/generic" >>/etc/postfix/main.cf 
postmap /etc/postfix/generic
service postfix restart


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM