Ubuntu下Postfix郵件服務器安裝及基本的設置

搞了好久,浪費我很多時間,終於把Ubuntu下postfix郵件服務器搭建搞定。。。不過偶沒玉米,只能在虛擬機之內網IP代替了。bash

具體操做:服務器

=======================齷齪的分割線=======================網絡

安裝 postfixdom

sudo apt-get install postfix工具

安裝mailx軟件包來用作mail命令郵件工具的程序。安裝這個包來安裝mail命令。post

sudo apt-get install mailx測試

測試默認的安裝ui

這樣添加一個用戶。spa

sudo useradd -m -s /bin/bash fmaster
sudo passwd fmaster
.net

用下面的命令來測試默認的安裝。

telnet localhost 25

Postfix將出現下面這樣的終端提示,這樣你就能夠輸入一些SMTP命令。

Trying 127.0.0.1…
Connected to mail.fossedu.org.
Escape character is ‘^]’.
220 localhost.localdomain ESMTP Postfix (Ubuntu)

在Postfix的提示符下面輸入這些代碼段。

ehlo localhost mail from: root@localhost rcpt to: fmaster@localhost data Subjet: My first mail on Postfix Hi, Are you there? regards, Admin . (Type the .[dot] in a new Line and press Enter ) quit

 

檢查’fmaster’的郵箱。

su – fmaster
mail

當你輸入mail}命令的時候,終端的輸出應該像下面這樣。

Mail version 8.1.2 01/15/2001. Type ? for help.
「/var/mail/fmaster」: 2 messages 2 new
>N 1 root@localhost      Mon Mar 6 12:49   13/479   Just a test
N 2 root@localhost      Mon Mar 6 12:51   15/487   My first mail
&

你會觀察到郵件被按照數字編號索引了,所以你能夠輸入你想看的郵件的編號。例如輸入’2′來閱讀第二封信。閱讀完畢使用」q」命令退出。郵件會被寫到用戶主目錄下面的一個叫作’mbox’的文件中。在咱們的例子中是’/home/fmaster/mbox’。

mbox型的郵箱中的全部消息被鏈接而且儲存成一個單一的文件。每個消息的開始被頭5個字母是」From」的那一行標示出來,而且每一封消息的末尾有一個空行。
設置Postfix支持Maildir型的郵箱

Maildir 是一個郵件池的格式,這種郵件格式不須要文件鎖定來保證消息的完整性,由於郵件以一個特有的名字被保存在一個個單獨的文件中。一個Maildir是一個包含3個叫作tmp, new和curd的子目錄的目錄(經常以Maildir命名)。這些子目錄應該在同一個文件系統中。

另外一個使用Maildir格式的郵箱的理由是Courier IMAP/POP3服務器只支持Maildir格式的郵箱。

在[這裏]可以獲得更多關於Maildir的信息。

sudo vi /etc/postfix/main.cf

加入下面的代碼:

home_mailbox = Maildir/

在’ mailbox_command = procmail -a 「$EXTENSION」 ‘那一行前面加上一個」#」將其註釋掉

重啓 Postfix 使改變生效。

sudo /etc/init.d/postfix restart

再一次測試你的安裝。
安裝 courier IMAP 和 POP3

sudo apt-get install courier-pop
sudo apt-get install courier-imap

爲postfix增長本地域

sudo   vi /etc/postfix/main.cf

將你的域名增長到 ‘mydestination’。增長完成後它看起來應該象這樣:


mydestination = mail.fossedu.org, localhost.localdomain, localhost, yourdoamin.com

將你的本地網絡增長到:

sudo vi /etc/postfix/main.cf

我假定你的本地網絡是 192.168.1.0/24 而且將你的本地網絡加入到{{{mynetworks}}}。完成後它看起來應該像這樣:

mynetworks = 127.0.0.0/8, 192.168.1.0/24

使Postfix從因特網上接收郵件

使用下面的命令在’/etc/postfix/main.cf’增長’inet_interfaces = all’

sudo vi /etc/postfix/main.cf

最後重啓Postfix;

sudo /etc/init.d/postfix restart

使用下面的代碼再一次測試你的安裝是否成功:

telnet mail.yourdomain.com 25
ehlo yourdmain.com
mail from: root@yourdomain.com
rcpt to: fmaster@yourdomain.com
data
Subject: My first mail for my domain
Hi,
Are you there?
regards,
Admin
. (and Enter In a new Line)
quit

檢查’fmaster’的郵箱

su – fmaster
cd Maildir/new
ls

如今你將看到郵件在一個個單獨的文件中了。
測試 Courier POP3

在終端中輸入:

telnet mail.yourdomain.com 110

使用下面示例代碼來測試。注意在你本身的環境中作適當的變通。輸出應該像下面這樣:

Connected to mail.yourdomain.com (69.60.109.217).
Escape character is ‘^]’.
+OK Hello there.

在Courier POP3服務器的提示符下面輸入下面的代碼段。我假定你可以看狀況輸入’+OK’後的行。

user fmaster
+OK Password required.
pass password
+OK logged in.
quit

測試 Courier IMAP

在終端輸入這些:

telnet mail.yourdomain.com 143

使用下面的示例代碼來測試。注意在你本身的環境中作適當的變通。輸出應該像下面這樣:

*OK [CAPABILITY IMAP4rev1 UIDPLUS CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA IDLE ACL ACL2=UNION STARTTLS
XCOURIEROUTBOX=INBOX.Outbox] Courier-IMAP ready. Copyright 1998-2005 Double Precision, Inc. See COPYING for distribution information.

在Courier POP3服務器的提示符下面輸入下面的代碼段

a login fmaster password
a OK LOGIN Ok.
a logout

相關文章
相關標籤/搜索