一,安裝Postfix和相關軟件包
1.安裝Postfix
apt-get install postfix
在安裝的過程當中,會提示輸入選擇類型和域名。
2.安裝mailx軟件包
apt-get install mailutils
mailx軟件包是一個命令行的郵件屬性程序,mail命令包含在mailx軟件包裏面
二,測試你的默認設置
1.添加測試用戶(以s爲例)
useradd -m -s /bin/bash s
passwd s
這裏密碼設置爲123456。在後述的測試中會用到。
2.用下面的命令測試,其實就是測試25端口是否打開
telnet localhost 25
3.Postfix將在終端中顯示以下提示,這樣你就能夠用來鍵入SMTP命令.
- root@ubuntu :~# telnet localhost 25
- Trying 127.0.0.1...
- Connected to localhost.
- Escape character is '^]'.
- 220 ubuntu ESMTP Postfix (Ubuntu)
4.編寫郵件併發送
root@ubuntu :~# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 ubuntu ESMTP Postfix (Ubuntu)
ehlo localhost //
250-ubuntu
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
mail from: root@localhost //
250 2.1.0 Ok
rcpt to: fmaster@localhost //
250 2.1.5 Ok
data //
354 End data with .
Subject: My first mail on Postfix //
this ia the first postfix mail . //
. //
250 2.0.0 Ok: queued as 661C75F796
quit //
221 2.0.0 Bye
Connection closed by foreign host.
5.切換到fmaster用戶,查看郵件
root@ubuntu :~# su - fmaster
fmaster@ubuntu:~$ mail
"/var/mail/fmaster": 1 message 1 new
>N 1 root@localhost 火 1月 29 12: 12/435 My first mail on Postfix
此時的郵件存放在/var/mail/fmaster文件中。
當這個郵件被打開以後,Postfix就會以mbox的風格處理郵件,
將郵件都保存到/home/fmaster/mbox這一個文件中。
6.設置Postfix以支持Maildir風格的郵箱(在修改配置以前備份配置文件)
- cp -pf /etc/postfix/main.cf /etc/postfix/main.cf_bak
- vim /etc/postfix/main.cf
在文件中末尾處,添加以下配置:
7.重啓postfix,以使配置生效
- /etc/init.d/postfix restart
8.測試
- root@ubuntu:/etc/postfix# telnet localhost 25
- Trying 127.0.0.1...
- Connected to localhost.
- Escape character is '^]'.
- 220 ubuntu ESMTP Postfix (Ubuntu)
- ehlo localhost //
- 250-ubuntu
- 250-PIPELINING
- 250-SIZE 10240000
- 250-VRFY
- 250-ETRN
- 250-STARTTLS
- 250-ENHANCEDSTATUSCODES
- 250-8BITMIME
- 250 DSN
- mail from: root@localhost //
- 250 2.1.0 Ok
- rcpt to: fmaster@localhost //
- 250 2.1.5 Ok
- data //
- 354 End data with .
- Subject: maildir test //
- this is a maildir style mail test . //
- . //
- 250 2.0.0 Ok: queued as 249315F80D
- quit //
- 221 2.0.0 Bye
- Connection closed by foreign host.
9.查收郵件這個時候Postfix會在/home/fmaster目錄下面生成一個名爲Maildir的文件夾,全部的郵件都保存在/home/fmaster/Maildir這個文件夾內。
- fmaster@ubuntu:~$ ll /home/fmaster/Maildir
- 合計 20
- drwx------ 5 fmaster fmaster 4096 1月 29 12:35 ./
- drwxr-xr-x 3 fmaster fmaster 4096 1月 29 12:35 ../
- drwx------ 2 fmaster fmaster 4096 1月 29 12:35 cur/
- drwx------ 2 fmaster fmaster 4096 1月 29 12:35 new/
- drwx------ 2 fmaster fmaster 4096 1月 29 12:35 tmp/
-
- fmaster@ubuntu:~/Maildir$ cd new
-
- fmaster@ubuntu:~/Maildir/new$ ll
- 合計 12
- drwx------ 2 fmaster fmaster 4096 1月 29 12:35 ./
- drwx------ 5 fmaster fmaster 4096 1月 29 12:35 ../
- -rw------- 1 fmaster fmaster 426 1月 29 12:35 1359430545.Vfc00I16daM671946.ubuntu
-
- fmaster@ubuntu:~/Maildir/new$ less 1359430545.Vfc00I16daM671946.ubuntu
- Return-Path:
- X-Original-To: fmaster@localhost
- Delivered-To: fmaster@localhost
- Received: from localhost (localhost [127.0.0.1])
- by ubuntu (Postfix) with ESMTP id 249315F80D
- for ; Tue, 29 Jan 2013 12:35:13 +0900 (JST)
- Subject: maildir test
- Message-Id: <20130129033517.249315F80D@ubuntu>
- Date: Tue, 29 Jan 2013 12:35:13 +0900 (JST)
- From: root@localhost
-
- this is a maildir style mail test .
- 1359430545.Vfc00I16daM671946.ubuntu (END)
到此爲止發送郵件的服務器就搭建成功了,接下來配置收信服務器。
在配置收信服務器中,須要使用到域名,若是沒有域名能夠修改hosts文件來進行測試。
下面配置中用到的域名: dotuian.com
郵件服務器的IP地址
: 192.168.0.114 (ubutun)
測試客戶端 : 192.168.0.80 (windows 7)
三,配置收信服務器
1.修改郵件服務器的hosts文件
在文件中添加
2.修改測試客戶端的hosts文件
以管理員權限運行一個文本編輯器,打開"C:\Windows\System32\drivers\etc\hosts",在裏面添加
- 192.168.0.114 dotuian.com
若是已經存在域名了,就不要上述的修改hosts文件的兩步了。
3.安裝收信服務器
- apt-get install courier-pop
- apt-get install courier-imap
4.修改配置文件
(a)將域名增長到"mydestination"。配置以下
- mydestination = localhost, ubuntu, localhost.localdomain, localhost, dotuian.com
(b)將本地網絡增長到"mynetworks"。由於服務器IP地址爲192.168.0.114,因此配置以下
- mynetworks = 192.168.0.0/24, 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
(c)爲了可以經過網絡接受郵件,修改"inet_interfaces"爲"all"
- #inet_interfaces = loopback-only
- inet_interfaces = all
5.重啓postfix服務器
- /etc/init.d/postfix restart
6.測試域名配置是否成功(a)經過域名dotuian.com發送郵件
- root@ubuntu:/etc/postfix# telnet dotuian.com 25
- Trying 127.0.0.1...
- Connected to dotuian.com.
- Escape character is '^]'.
- 220 ubuntu ESMTP Postfix (Ubuntu)
- ehlo dotuian.com //
- 250-ubuntu
- 250-PIPELINING
- 250-SIZE 10240000
- 250-VRFY
- 250-ETRN
- 250-STARTTLS
- 250-ENHANCEDSTATUSCODES
- 250-8BITMIME
- 250 DSN
- mail from: shou@dotuian.com //
- 250 2.1.0 Ok
- rcpt to: fmaster@dotuian.com //
- 250 2.1.5 Ok
- data //
- 354 End data with .
- Subject: mail test with domain //
- this is a test mail . //
- dotuian.com //
- .
- 250 2.0.0 Ok: queued as 9E95D5F809
- quit //
- 221 2.0.0 Bye
- Connection closed by foreign host.
(b)查收郵件檢查/home/fmaster/Maildir/new,能夠看到新建了一個獨立的文件
- fmaster@ubuntu:~/Maildir/new$ ll
- 合計 16
- drwx------ 2 fmaster fmaster 4096 1月 29 14:10 ./
- drwx------ 5 fmaster fmaster 4096 1月 29 12:35 ../
- -rw------- 1 fmaster fmaster 426 1月 29 12:35 1359430545.Vfc00I16daM671946.ubuntu
- -rw------- 1 fmaster fmaster 446 1月 29 14:10 1359436215.Vfc00I16d8M538132.ubuntu
-
- fmaster@ubuntu:~/Maildir/new$ less 1359436215.Vfc00I16d8M538132.ubuntu
-
- Return-Path:
- X-Original-To: fmaster@dotuian.com
- Delivered-To: fmaster@dotuian.com
- Received: from dotuian.com (localhost [127.0.0.1])
- by ubuntu (Postfix) with ESMTP id 9E95D5F809
- for ; Tue, 29 Jan 2013 14:09:35 +0900 (JST)
- Subject: mail test with domain
- Message-Id: <20130129050947.9E95D5F809@ubuntu>
- Date: Tue, 29 Jan 2013 14:09:35 +0900 (JST)
- From: shou@dotuian.com
-
- this is a test mail .
- dotuian.com
- 1359436215.Vfc00I16d8M538132.ubuntu (END)
7.測試Courier POP3
- root@ubuntu:/etc/postfix# telnet dotuian.com 110
- Trying 127.0.0.1...
- Connected to dotuian.com.
- Escape character is '^]'.
- +OK Hello there.
- user fmaster //
- +OK Password required.
- pass test1234 //
- +OK logged in.
- quit //
- +OK Bye-bye.
- Connection closed by foreign host.
8.測試 Courier IMAP
- root@ubuntu:/etc/postfix# telnet dotuian.com 143
- Trying 127.0.0.1...
- Connected to dotuian.com.
- Escape character is '^]'.
- * OK [CAPABILITY IMAP4rev1 UIDPLUS CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA IDLE ACL ACL2=UNION] Courier-IMAP ready. Copyright 1998-2011 Double Precision, Inc. See COPYING for distribution information.
- a login fmaster test1234 //
- a OK LOGIN Ok.
- a logout //
- * BYE Courier-IMAP server shutting down
- a OK LOGOUT completed
- Connection closed by foreign host.
9.經過Microsoft Outlook收發郵件是的配置