您的位置:首页 > 其它

suse架设postfix邮件服务器

2014-04-25 18:19 197 查看


环境:

Suse Linux Enterprise Server 11(x86_64) SP1

Postfix 需要安装的组件
套 件 名 稱
簡 單 描 述
postfix
SMTP Server 的主要套件。
qpopper
POP3 Server 的主要套件。
需先切到root用户
zypper install postfix
suse使用qpopper来作为pop3工具,qpopper 自行下载
rpm -ivh [b]qpopper-4.0.14-1.1.x86_64.rpm[/b]
Tips:欲架設具認證功能的郵件主機時,尚需多裝 cyrus-sasl及cyrus-sasl-saslauthd這兩個套件。
如果你没有域名,可以通过下面:
1.修改邮件服务器的hosts文件

vim /etc/hosts

在文件中添加

127.0.0.1 yourdomain.com

2.修改测试客户端的hosts文件

以管理员权限运行一个文本编辑器,打开"C:\Windows\System32\drivers\etc\hosts",在里面添加

192.168.0.114 yourdomain.com

檢視套件內容
suse:~ # rpm -ql postfix
/etc/postfix/main.cf
Postfix 的主要設定檔。
/etc/postfix/transport
擔任 Mail GW 的主機,可以藉由設定這個檔案,來將信件轉給指定的 MTA。
/etc/init.d/postfix
管理 Postfix 服務的 script。
/sbin/rcpostfix
連結至 /etc/init.d/postfix 的符號連結檔。
/usr/lib/postfix/master
提供 Postfix 服務的 daemon。
/usr/bin/mailq
查詢郵件佇列 (mail queue) 的指令。
/usr/bin/newaliases
建立或更新郵件別名資料庫。
/usr/sbin/postalias
維護 Postfix 別名資料庫。
/usr/sbin/postconf
Postfix 的設定工具。
/usr/sbin/postfix
控管 Postfix 的程式。
/usr/sbin/postmap
可將指定的檔案內容轉換成資料庫格式,並將轉換後的結果寫入資料庫檔案裡。
/usr/sbin/postsuper
管理佇列郵件的工具。
/var/spool/postfix
安置處理佇留信件的相關目錄,如 hold、incoming、active 及 deferred 等。
 針對此套件內容裡的 /usr/sbin/postconf 及 /usr/sbin/postfix指令做個補充:
/usr/sbin/postconf:
此為 Postfix 的設定工具,可以用來列出 Postfix 的預設參數及實際參數值,也可以直接在命令列上編輯設定參數,並將結果寫入 main.cf 中。舉例如下:
suse:~ # postconf

# 列出 Postfix
目前真實的設定參數值。

suse:~ # postconf -d

# 列出 Postfix
預設的設定參數值。

suse:~ # postconf -e 'alias_maps = hash:/etc/postfix/aliases'

# 在命令列上編輯設定參數後,會直接寫入main.cf中。
/usr/sbin/postfix:
這是 postfix 的控管程式,可用來啟動、停止、重新載入 postfix 服務。舉例如下:
suse:~ # postfix stop [start|reload]

# 這應該沒問題。

suse:~ # postfix flush

# 將佇留信件強迫寄出。


設定開機時啟動 Postfix 服務

suse:~ # chkconfig postfix 35
17.3.2 設定簡易的 Postfix Server
 這一小節會先設定一些 Postfix 的基本參數,等 Postfix 能正常運作之後,再來進一步探討其他的參數設定。另外這裡是把 SMTP 及 POP3 Server 都架設在同一部主機上,這樣在實作上也會比較單純及方便。

設定 SMTP Server
suse:/etc/postfix #vi main.cf

# The queue_directory specifies the location of the Postfix queue.

queue_directory = /var/spool/postfix

# 這是佇留信件所存放的目錄位置。 # The command_directory parameter specifies the location of all postXXX commands.

command_directory = /usr/sbin

# 指定所有 postxxx
指令 (如 postfix、postalias、postconf 等) 所存放的目錄位置。

# The daemon_directory parameter specifies the location of all Postfix daemon programs

# (i.e. programs listed in the master.cf file). This directory must be owned by root.

daemon_directory = /usr/lib/postfix

# 指定所有 Postfix
相關 daemon 所存放的目錄位置。

# The mail_owner parameter specifies the owner of the Postfix queue and of most

# Postfix daemon processes.

mail_owner = postfix

# 指定 Postfix
佇列目錄的擁有者及大部分 Postfix daemon 程序的執行身分。

# The myhostname parameter specifies the internet hostname of this mail system.

# $myhostname is used as a default value for many other configuration parameters.

myhostname = mta.paching.idv.tw

# 指定您 Mail Server在 Internet 上的完整主機名稱。

# The mydomain parameter specifies the local internet domain name.

# The default is to use $myhostname minus the first component.

# $mydomain is used as a default value for many other configuration parameters.

mydomain = paching.idv.tw

# 指定本地端的網域名稱,也就是把 $myhostname去除最前頭的 Short hostname 即是。

# 如果 myhostname 設定為 paching.idv.tw,那 mydomain 就是 idv.tw。

# For the sake of consistency between sender and recipient addresses,myorigin also

# specifies the default domain name that is appended to recipient addresses that

# have no @domain part.

myorigin = $mydomain

# 當您在 Postfix
主機上發信時,在對方收到信件後,會顯示寄件者的郵件地址為

# xx@[$myorigin],以這裡來說就是 xx@paching.idv.tw。

# 另外要直接指派也行:# myorigin = paching.idv.tw

# 如果您有設定郵件別名 (參考 17.4 節) 時,也會使用到這個參數的設定。

# The inet_interfaces parameter specifies the network interface addresses that this mail

# system receives mail on. By default, the software claims all active interfaces on the

# machine.

# Note: you need to stop/start Postfix when this parameter changes.

inet_interfaces = all

# 指定在郵件主機上,允許接收信件的網路介面位址。all是表示所有網路介面都可以

# 接收使用者所寄來的信件,這也是預設值。

# 另外當您修改了這個參數後,需要重新啟動 Postfix,而不是重新載入。

# The mydestination parameter specifies the list of domains that this machine considers

# itself the final destination for.

mydestination = $mydomain

# Mail Server
是否會將此封信當成本地端的信件來處理,就是靠這個參數來決定的。比如

# 以這裡的設定來說,只要收到的信件地址是 xxx@paching.idv.tw,則此 MTA 都會視為

# 本地端的信件。如您有多個網域名稱時,在這些名稱之間可使用空白鍵或「,」隔開。

# By default (mynetworks_style = subnet), Postfix "trusts" SMTP clients in the same IP

# subnetworks as the local machine.

# Specify "mynetworks_style = class" when Postfix should "trust" SMTP clients in the

# same IP class A/B/C networks as the local machine.

# Specify "mynetworks_style = host" when Postfix should "trust" only the local machine.

mynetworks_style = subnet

# 指定 SMTP所信任的來源端類型,至於可以指定的類型有以下三種:

# mynetworks_style = subnet

# 只要與 MTA位於同一個子網段的主機,其所寄過來的信件都允許 Relay。此乃預設。

# mynetworks_style = class

#只要與 MTA位於同一 IP 類型 (Class A/B/C) 的主機,其所寄過來的信件都允許 Relay。

# mynetworks_style = host

#只允許本機 Relay,也就是只能在郵件主機上來寄信的意思。

# Alternatively, you can specify the mynetworks list by hand, in which case Postfix ignores

# the mynetworks_style setting.

# Specify an explicit list of network/netmask patterns, where the mask specifies the number

# of bits in the network part of a host address.

mynetworks = 192.168.1.0/24,127.0.0.0/8

# 指定 SMTP
所信任的來源端位址。以這裡的設定來說,只要是從 192.168.1.0/24 這個

# 網路段所寄過來的信件,或是直接在本機寄信時,都允許 Relay。

# 另外當 mynetworks_style及 mynetworks 同時做設定時,mynetworks_style 會被忽略掉。



always_bcc = david@paching.idv.tw

# 這個參數可將 postfix所有收發的信件,利用密件副本的方式寄給其後所指定的帳號。



message_size_limit = 10240000

# 設定每封信件大小不得超過 10 MB。
main.cf 中勿加home_mailbox=Mailbox/
不然telnet IP 110时,收不到邮件,会出现has 0 visible message 或者你使用outlook等客户端时收不到邮件,

 以上就是一些基本的設定參數。如您 Postfix 目前尚未啟動,則請使用以下任何一種方式來啟動吧:
suse:~ #/etc/init.d/postfix start

suse:~ # rcpostfix start

suse:~ # postfix start
 將來要是作了任何的修改,那執行「rcpostfix restart」或「postfix reload」就行了。
SMTP 啟動之後的檢查
1. 本機使用 netstat 或 ps 指令檢查
suse:~ # netstat -anp | grep :25

tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 11348/master

       ↑

這裡如果顯示 127.0.0.1 的話,表示不能對外提供 smtp 服務,請您特別留意一下。 

suse:~ # ps aux | grep master

root 11348 0.0 0.5 4736 1432 ? Ss 18:17 0:00 /usr/lib/postfix/master
2.
3. Client 端使用 telnet 測試
Windows Client 的測試
C:\> telnet 192.168.1.111 25

220 mta.paching.idv.tw ESMTP Postfix
看到這一行就對了。

Linux Client 的測試 (順便模擬與 SMTP 的對話)
Client:~ # telnet 192.168.1.111 25

Trying 192.168.1.111...

Connected to 192.168.1.111.

Escape character is '^]'.

220 mta.paching.idv.tw ESMTP Postfix

helo client.paching.idv.tw

# 先使用 helo指令來介紹自己所在的主機。

250 mta.paching.idv.tw

mail from: barry@paching.idv.tw

# 使用 mail from
指令來讓 SMTP Server 了解寄件者的郵件地址。

250 Ok

rcpt to: mary@paching.idv.tw

# 使用 rcpt to
指令來讓 SMTP Server 知道收件者的郵件地址。

# 請務必確定郵件主機上存在著 mary
的帳號。

250 Ok

data 

# 使用 data
指令來表示開始要撰寫信件的內容了。

354 End data with <CR><LF>.<CR><LF>

subject: test←這封信的主旨。以下就是信件的內容囉。

Hello mary, i am barry.

How are you ?


.←最後輸入個「.」,來表示信件已撰寫完畢。接著
SMTP就會開始處理您的信件了。

250 Ok: queued as 5F2155E6A

quit←退出與 SMTP Server的對話。

221 Bye

Connection closed by foreign host.
設定 POP3 Server
 目前這台 Mail Server 只能提供寄信的服務,還不能提供給您的 Client 端收信,所以趕快去設定一下 POP3 就行了。POP3 服務是靠 xinetd 來啟動的,因此待會兒做完修改後,請記得重新啟動 xinetd。
suse:~ # vi /etc/xinetd.d/qpopper

service pop3

{

    disable    = no ←原本為 yes,改成 no 即可。

    socket_type  = stream

    protocol    = tcp

    wait      = no

    user      = root

    server     = /usr/sbin/popper

    server_args   = -s

    flags     = IPv4

}

suse:~ # rcxinetd restart
POP3 啟動之後的檢查
1. 本機使用 netstat 指令檢查
suse:~ # netstat -anp | grep :110

tcp 0 0 0.0.0.0:110 0.0.0.0:* LISTEN 12082/xinetd
2.
3. Client 端使用 telnet 測試
Windows Client 的測試
C:\> telnet 192.168.1.111 110

+OK ready <7684.1132788310@suse>
Linux Client 的測試 (順便模擬與 POP3 的對話)
Client:~ # telnet 192.168.1.111 110

Trying 192.168.1.111...

Connected to 192.168.1.111.

Escape character is '^]'.

+OK ready <7752.1132790189@suse>

user mary

# 使用 user指令來指出您在 POP3 Server 上的帳號。

+OK Password required for mary.

pass mypasswd

# 使用 pass指令來輸入 mary 的密碼。

+OK mary has 1 visible message (0 hidden) in 529 octets.

list

# 列出信件一覽表。

+OK 1 visible messages (529 octets)

1 529

.

retr 1

# 使用 retr指令來查看第一封信件的內容。

+OK 529 octets

Return-Path: <barry@paching.idv.tw>

X-Original-To: mary@paching.idv.tw

Delivered-To: mary@paching.idv.tw

Received: from client.paching.idv.tw (client.paching.idv.tw [192.168.1.188])

by mta.paching.idv.tw (Postfix) with SMTP id E8FC5155

for <mary@paching.idv.tw>; Thu, 24 Nov 2005 07:53:30 +0800 (CST)

subject: test

Message-Id: <20051123235330.E8FC5155@mta.paching.idv.tw>

Date: Thu, 24 Nov 2005 07:53:30 +0800 (CST)

From: barry@paching.idv.tw

To: undisclosed-recipients:;

X-UIDL: V9+!!7WP!!Pda"!N?L!!
Hello mary, i am barry.

How are you ?
.

dele 1←刪除第一封信。

+OK Message 1 has been deleted.

quit←退出與 POP3 Server的對話。

+OK Pop server at suse signing off.

Connection closed by foreign host.
您可以配置outlook,来检验能否收发邮件

转载参考:
http://www.suse.url.tw/sles10/lesson17.htm http://blog.csdn.net/dotuian/article/details/8552418
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: