1.查找使用者群組
#grep postfix /etc/group
#grep postfix /etc/passwd
安裝postfix
#yum -y install postfix
2.先備份main.cf
[[email protected] ~]# cd /etc/postfix
[[email protected] postfix]# cp main.cf main.cf.bak
3.編輯main.cf
myhostname = mail.1a-CentOSserver.com
mydomain = 1a-centosserver.com
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
mynetworks = 192.168.13.0/24, 127.0.0.0/8
relay_domains = $mydestination
home_mailbox = Maildir/
mydomain: mydomain參數是指email伺服器的域名,請確定為正式域名(如centos.bz)
myhostname: myhostname參數是指系統的主機名稱(如我的伺服器主機名稱是mail.centos.bz)
myorigin: myorigin參數指定本地發送郵件中來源和傳遞顯示的域名。在我們的例子中,mydomain是centos.bz,也是我的域名。
對于下面的一行,我們的郵件位址是[email protected]而不是[email protected]。
myorigin = $mydomain
mynetworks: mynetworks參數指定受信任SMTP的清單,具體的說,受信任的SMTP用戶端允許通過
Postfix傳遞郵件。
mydestination: mydestination參數指定哪些郵件位址允許在本地發送郵件。這是一組被信任的允許通過伺服器發送或傳遞郵件的IP位址。使用者試圖通過發送從此處未列出的IP位址的原始伺服器的郵件将被拒絕。 inet_interfaces: inet_interfaces參數設定網絡接口以便Postfix能接收到郵件。
relay_domains: 該參數是系統傳遞郵件的目的域名清單。預設為mydestination,如果留白,我們保證了我們的郵件伺服器不對不信任的網絡開放。
home_mailbox: 該參數設定郵箱路徑與使用者目錄有關,也可以指定要使用的郵箱風格。
4.開放SMTP的25端口
#iptables -A INPUT -p tcp --dport 25 -j ACCEPT
#service iptables save
5.通過telnet測試發送郵件
如果telnet沒有,用#yum install telnet安裝
[[email protected] sysconfig]# telnet 127.0.0.1 25
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
220 mail.apmro.com.sg ESMTP Postfix
MAIL FROM:<[email protected]>
250 2.1.0 Ok
RCPT TO:[email protected]
250 2.1.5 Ok
DATA
354 End data with <CR><LF>.<CR><LF>
FROM:[email protected]
TO:[email protected]
Subject:test message
test body
.
250 2.0.0 Ok: queued as 11F9340372
quit
221 2.0.0 Bye
Connection closed by foreign host.
[[email protected] sysconfig]#
成功收到test郵件
5.安裝Cyrus
#yum install cyrus*
安裝完成之後,修改/etc/postfix/main.cf
local_recipient_maps = //209行,把前面的注釋拿掉。 local_recipient_maps設定成empty意思就是
# To turn off local recipient checking in the SMTP server, specify
# local_recipient_maps = (i.e. empty).
smtpd_banner = $myhostname ESMTP unknow //568行,把前面的注釋拿掉,然後把$mail_name ($mail_version)改成unknow
mailbox_transport=lmtp:unix:/var/lib/imap/socket/lmtp //設定連接配接cyrus-imapd的路徑
//在main.cf檔案的底部加上以下内容
smtpd_sasl_auth_enable = yes //使用SMTP認證
broken_sasl_auth_clients = yes //讓不支援RFC2554的smtpclient也可以跟postfix做互動。
smtpd_sasl_local_domain = $myhostname // 指定SMTP認證的本地域名
smtpd_sasl_security_options = noanonymous //取消匿名登陸方式
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination //設定郵件中有關收件人部分的限制
smtpd_sasl_security_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination //設定允許範圍
message_size_limit = 15728640 //郵件大小
6.編輯/etc/sasl2/smtpd.conf
[[email protected] sasl2]# vi smtpd.conf
pwcheck_method: saslauthd
mech_list: plain login
添加下面兩行
log_level: 3
saslauthd_path: /var/run/saslauthd/mux
7.啟動服務
[[email protected] etc]# service postfix restart
Shutting down postfix: [ OK ]
Starting postfix: [ OK ]
[[email protected] etc]# service saslauthd start
Starting saslauthd: [ OK ]
[[email protected] etc]# service cyrus-imapd start
Importing cyrus-imapd databases: [ OK ]
Starting cyrus-imapd: [ OK ]
8.安裝cyrus之後會自動建立一個cyrus系統使用者,
#passwd cyrus更改這個使用者的密碼
9.驗證sasl-authd,如果現實OK“success”說明正常。
[[email protected] etc]# testsaslauthd -u cyrus -p '密碼必須用單引号括起來'
0: OK "Success."
10.用cyrus 建立郵件賬戶
[r[email protected] etc]# id cyrus
uid=76(cyrus) gid=12(mail) groups=12(mail),76(saslauth)
cyrus-imapd服務的配置檔案有以下3個。
/etc/sysconfig/cyrus-imapd:用于啟動cyrus-imapd服務的配置檔案。
/etc/cyrus.conf:是cyrus-imapd服務的主要配置檔案,其中包含該服務中各個元件(IMAP、POP3、sieve和NNTP等)的設定參數。
/etc/imapd.conf:是cyrus-imapd服務中的IMAP服務的配置檔案。
通過#telnet localhost 110測試pop3
2.ERR: USER command only available under a layer
在/etc/imap.conf中添加: allowplaintext:yes
[[email protected] crazywill]$ telnet pop.163.com 110 #telnet登入110端口
Trying 202.108.5.104...
Connected to pop.163.com.
Escape character is '^]'.
+OK Welcome to coremail Mail Pop3 Server (163com[20050206])
USER [email protected] # 使用者名不需要base64編碼
+OK core mail
PASS mypassword # 登入密碼
+OK 254 message(s) [27676669 byte(s)]
STAT # 檢視郵箱狀态
+OK 254 27676669
LIST # 郵件清單
+OK 254 27676669
1 2468
2 21945
3 33136
4 2071
5 3364
6 18906
7 3136
8 24764
.................
TOP 254 0 # 檢視指定郵件的郵件頭,0表示檢視整個郵件頭,其它正整數表示限制傳回多少行。
+OK core mail
Received: from smtp.63.com (unknown [58.252.70.158])
by smtp5 (Coremail) with SMTP id wKjREDrA9gIfFqlEjCnRAg==.29062S4;
Mon, 03 Jul 2006 21:07:18 +0800 (CST)
TO: [email protected]
FROM : [email protected] # 這裡即前面發信時僞造的一個假發送人資訊,平時正常操作隻顯示這個。
SUBJECT: test by telnet/smtp # 郵件主題
Message-Id: <44A91687.0E6F6C.07562>
Date: Mon, 3 Jul 2006 21:07:19 +0800 (CST)
Sender: [email protected] # 這裡是真正的發送人,不可僞造。
.
RETR 254 # 擷取指定郵件
+OK 354 octets
Received: from smtp.63.com (unknown [58.252.70.158])
by smtp5 (Coremail) with SMTP id wKjREDrA9gIfFqlEjCnRAg==.29062S4;
Mon, 03 Jul 2006 21:07:18 +0800 (CST)
TO: [email protected]
FROM : [email protected]
SUBJECT: test by telnet/smtp
Message-Id: <44A91687.0E6F6C.07562>
Date: Mon, 3 Jul 2006 21:07:19 +0800 (CST)
Sender: [email protected]
test, just a test.
.
DELE 254 # 删除第254封郵件
+OK core mail
STAT # 檢視郵箱狀态
+OK 253 27676315
QUIT # 退出
+OK core mail
Connection closed by foreign host.
[[email protected] crazywill]$
cryadm
用“cyradm”可以建立、删除、限制和控制郵箱(詳細可看幫助)。可用“cyradm ”指令啟動,提示符将變成“>”。你可以用“help”指令,将會出現如下資訊:
createmailbox, cm create a mailbox
deleteaclmailbox, dam delete an ACL on a mailbox
deletemailbox, dm delete a mailbox
help get help on commands
listaclmailbox, lam list the ACL on a mailbox
listmailbox, lm list mailboxes
listquota, lq list quota on root
listquotaroot, lqr, lqm list quota roots on mailbox
quit exit program
renamemailbox, renm rename a mailbox
setaclmailbox, sam set an ACL on a mailbox
setquota, sq set quota limits
注意:如果你的系統中,Kerberos v4 沒有在運作,那你必須為使用者設定密碼。
根據郵箱的命名慣例,要求任何使用者的第一級郵箱(收件箱)必須時“user.”格式的。可以用如下指令建立一個新郵箱:
createmailbox user.
比如為userid為"smith"的使用者建立郵箱,可用如下指令:
createmailbox user.smith
用如下指令可限制空間:
setquota user.smith 10000。
[[email protected] crazywill]$ telnet 192.168.0.1 143 #telnet登入IMAP協定的143端口
Trying 192.168.0.1...
Connected to xxxxxx
Escape character is '^]'.
* OK xxxxxxx System IMap Server Ready
A01 LOGIN abc 123 #使用者登入
A01 OK LOGIN completed
A02 LIST "" * #列出所有信箱清單
* LIST () "/" "INBOX"
* LIST () "/" "Drafts"
* LIST () "/" "Sent Items"
* LIST () "/" "Trash"
* LIST () "/" "Junk E-mail"
* LIST () "/" "Virus Items"
* LIST () "/" "&XfJT0ZABkK5O9g-"
* LIST () "/" "&g0l6Pw-"
* LIST () "/" "&XfJT0ZABkK5O9g-/DailyReport"
* LIST () "/" "Jira"
* LIST () "/" "Admin"
* LIST () "/" "&V4NXPpCuTvY-"
A02 OK LIST Completed
A03 Select INBOX #選擇收件箱
* 37 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 1] UIDs valid
* FLAGS (/Answered /Seen /Deleted /Draft)
* OK [PERMANENTFLAGS (/Answered /Seen /Deleted /Draft)] Limited
A03 OK [READ-WRITE] SELECT completed
A04 Search ALL #查詢收件箱所有郵件
* OK X-SEARCH in progress
* OK X-SEARCH in progress
* OK X-SEARCH in progress
* SEARCH 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
A04 OK SEARCH completed # 列出符合條件的郵件序号(ALL表示列出目前信箱INBOX中的所有郵件)
A05 Search new #查詢收件箱所有新郵件
* OK X-SEARCH in progress
* OK X-SEARCH in progress
* OK X-SEARCH in progress
* SEARCH
A05 OK SEARCH completed #找不到任何新郵件
A06 Fetch 5 full #擷取第5封郵件的郵件頭
* 5 FETCH (INTERNALDATE "27-Jun-2006 14:00:27 +0800" FLAGS (/Seen) ENVELOPE ("Tue, 27 Jun 2006 13:56:51 +0800" "test " (("xxxxxx" NIL "xxxx" "xxxxxx")) (("xxxxxx" NIL "xxxx" "xxxxxx")) (("xxxxxx" NIL "xxxx" "xxxxxx")) ((NIL NIL "xxx" "xxxxx")) NIL NIL NIL "<[email protected] >") BODY (("text" "plain" ("charset" "gb2312") NIL NIL "base64" 14 2) ("text" "html" ("charset" "gb2312") NIL NIL "base64" 420 7) "alternative") RFC822.SIZE 1396)
A06 OK Fetch completed
A07 Fetch 5 rfc822 #擷取第5封郵件的完整内容
* 5 FETCH (RFC822 {1396}
[這裡是郵件内容,太長,略...]
A07 OK Fetch completed
A08 Fetch 5 flags #查詢第5封郵件的标志位
A08 OK Fetch completed
A09 Store 5 +flags.silent (/deleted) #設定标志位為删除
A09 OK STORE completed
A10 Expunge #永久删除目前郵箱INBOX中所有設定了/deleted标志的信件
A10 OK EXPUNGE completed
A11 noop # 空語句
A11 OK NOOP completed
A20 LOGOUT #退出
* BYE IMAP4rev1 Server logging out
A20 OK LOGOUT completed
Connection closed by foreign host.
[[email protected] crazywill]$
======= 關于外網telnet不上postfix 25的問題。
postfix安裝好之後,本地telnet 127.0.0.1 25是正常的。但是在另外一台機器上telnet ip 25的話,一直報no route use,也不是報connect refuse。外網更加連不上了,
一開始以為防火牆設定有問題,但是防火牆25,110,143端口都開放着,後來看到有些人用iptables -F清楚了所有規則的做法,結果死馬當活馬醫,也就照搬執行了一下,結果外網也能telnet '公網ip' 25了。不知道為什麼