注:本文的郵件服務器只用于發送郵件,也就是stmp服務器。
一、準備工作
1. 為郵件服務器添加dns解析
雖然不加dns解析也能把郵件發出去,但會被大多數郵件服務器當作垃圾郵件。根據我們的實際經驗,需要添加三條dns解析記錄:a記錄、mx記錄、txt記錄。比如域名cnblogs.info,對應的dns記錄如下:
2. 準備存放郵件的硬盤空間
如果用的是阿里云入門級linux服務器,有一塊20g的數據盤未掛載,需要格式化并掛載(假設這里掛載的目錄是/data)。
二、配置postfix
postfix是centos默認安裝的郵件服務器軟件。以下配置示例假設要配置的域名是cnblogs.info,郵件服務器主機名是mail.cnblogs.info。
1. 打開postfix的配置文件
1
|
vi /etc/postfix/main .cf |
2. :75 光標移至第75行,修改myhostname
1
|
myhostname = mail.cnblogs.info |
3. :83 光標移至第83行,修改mydomain
1
|
mydomain = jb51.info |
4. :99 光標移至第99行,修改myorigin
1
|
myorigin = $mydomain |
5. :116光標移至第116行,修改inet_interfaces
1
|
inet_interfaces = all |
6. :119光標移至第119行,修改inet_protocols
1
|
inet_protocols = ipv4 |
7. :164光標移至第164行,添加$mydomain
1
|
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain |
8. :264光標移至第264行,修改mynetworks
1
|
mynetworks = 127.0.0.0 /8 |
子網掩碼(netmask)轉換器:network and ip address calculator
9. :419 光標移至第419行,設置home_mailbox
1
|
home_mailbox = maildir/ |
10. :425 光標移至第425行,設置mail_spool_directory,/data是之前掛載的數據盤,mail目錄需要通過mkdir命令創建
1
|
mail_spool_directory = /data/mail |
11. 重啟postfix使設置生效
1
|
service postfix restart |
三、用telnet測試郵件服務器是否正常
1. 在郵件服務器上安裝telnet
1
|
yum install telnet |
2. 連接服務器smtp端口
1
|
telnet 127.0.0.1 25 |
3. 填寫發件人
1
|
mail from: test @jb51.info |
回車
4. 填寫收件人
1
|
rcpt to:contact@jb51.net |
回車
5. 撰寫郵件內容
5.1 開始寫郵件內容
data
回車
5.2 輸入標題
1
|
subject: test message |
回車
5.3 輸入內容,并以.號結束
1
2
|
test body . |
如果顯示下面的信息,說明郵件進入發送隊列
250 2.0.0 ok: queued as 88d6d32a94
四、授權其他服務器通過該郵件服務器發送郵件
未授權的情況下,如果在其他服務器telnet這臺服務器,在輸入收件人之后會出現relay access denied錯誤
1
2
|
rcpt to:contact@jb51.net 554 5.7.1 <contact@jb51.net>: relay access denied |
解決方法:
vi /etc/postfix/main.cf,:264將光標移至第264行,在mynetworks的值之后加這臺的服務器ip地址,比如:
1
|
mynetworks = 127.0.0.0 /8 58.33.14.124 |
service postfix restart之后,問題解決。
五、其他問題
收到上面telnet發出的郵件時,你會發現收件人信息顯示的是undisclosed recipients,解決方法是在data命令之后,輸入subject之前,分別輸入:
1
2
|
from: test @jb51.info to:contact@jb51.net |
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。
原文鏈接:http://www.cnblogs.com/dudu/archive/2012/12/12/linux-postfix-mailserver.html