RHEL6 Postfix+Dovecot郵件系統配置指南

  下午閒來無事,就在RHEL6上面折騰了下郵件的收發,rhel5默認採用sendmail做爲MTA,rhel6則採用postfix,以前也從來沒玩過這個,因此今天折騰的時候遇到了蠻多的阻力,現在基本實現了郵件的收發功能,更多的postfix配置後期還需要不斷的學習和整理,下面附上實驗過程

1:環境介紹
郵件服務器IP: 192.168.50.24/24,主機名爲rhel6.766.com,因爲懶得去配dns,這裏就用hosts文件來代替解析
客戶端1   IP: 192.168.50.211/24,FreeBSD 8.1,使用telnet收信
客戶端2   IP:  192.168.50.40/24,  Win7,使用foxmail收發郵件

[root@rhel6 ~]# hostname
rhel6.766.com
[root@rhel6 ~]# cat /etc/hosts
192.168.50.24   rhel6.766.com           rhel6
127.0.0.1       localhost.localdomain   localhost

2:安裝postfix和dovecot軟件包,這裏爲了省事,就採用rpm包方式安裝,後期可以去研究研究如何編譯使用,rhel6默認已經安裝好了postfix,所以只需要安裝dovecot即可

[root@rhel6 ~]# rpm -qa |grep -E 'postfix|dovecot|sendmail +'
postfix-2.6.6-2.el6.x86_64
dovecot-2.0-0.10.beta6.20100630.el6.x86_64


3:修改postfix主配置文件如下,各配置項的具體含義可以參考手冊和註釋
[root@rhel6 ~]# grep -v '^#' /etc/postfix/main.cf  |grep -v '^$'
queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
mail_owner = postfix
mydomain = rhel6.766.com      //指定郵件域
myorigin = $mydomain
inet_interfaces = all
inet_protocols = all
mydestination = $myhostname, localhost.$mydomain, localhost
unknown_local_recipient_reject_code = 550
mynetworks_style = subnet
mynetworks = 192.168.50.0/24, 127.0.0.0/8      //指定允許中繼的IP地址段
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases 
debug_peer_level = 2
debugger_command =
         PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
         ddd $daemon_directory/$process_name $process_id & sleep 5
sendmail_path = /usr/sbin/sendmail.postfix
newaliases_path = /usr/bin/newaliases.postfix
mailq_path = /usr/bin/mailq.postfix
setgid_group = postdrop
html_directory = no
manpage_directory = /usr/share/man
sample_directory = /usr/share/doc/postfix-2.6.6/samples
readme_directory = /usr/share/doc/postfix-2.6.6/README_FILES

[root@rhel6 ~]# service postfix start
啓動 postfix: [確定]

本地發信測試
[root@rhel6 ~]# mail -s 'Postfix1'[email protected]< /etc/hosts


win7客戶端測試:

 



 

4:修改dovecot主配置文件如下
[root@rhel6 ~]# grep -v '^#' /etc/dovecot/dovecot.conf |grep -v '^$' |grep -v '#'
!include conf.d/*.conf           //該配置項說明conf.d下的所以conf結尾的文件均有效,注意最前面的"!"號
protocols = imap pop3 lmtp
login_trusted_networks = 192.168.50.0/24   //指定允許登錄的網段地址
dict {
}

若未設置login_trusted_networks參數值,使用telnet登錄110端口,將會出現如下錯誤,不知道這個值能不能設置爲四個零,這個還有待測試…

freebsd# telnet 192.168.50.24 110
Trying 192.168.50.24...
Connected to 192.168.50.24.
Escape character is '^]'.
+OK Dovecot ready. <[email protected]>
user oracle
-ERR Plaintext authentication disallowed on non-secure (SSL/TLS) connections.
pass oracle
-ERR Plaintext authentication disallowed on non-secure (SSL/TLS) connections.
quit
+OK Logging out
Connection closed by foreign host.

[root@rhel6 ~]# tail -f /var/log/maillog
Dec 21 16:51:00 rhel6 dovecot: pop3-login: Aborted login (tried to use disabled plaintext auth): rip=192.168.50.211, lip=192.168.50.24, mpid=0

5:設置/etc/dovecot/conf.d/10-mail.conf配置文件如下:
[root@rhel6 ~]# grep -v '^#' /etc/dovecot/conf.d/10-mail.conf  |grep -v '^$' |grep -v '#'
mail_location = mbox:~/mail:INBOX=/var/mail/%u
mbox_write_locks = fcntl

如未設置mail_location參數值,將會出現如下錯誤:
freebsd# telnet 192.168.50.24 110
Trying 192.168.50.24...
Connected to 192.168.50.24.
Escape character is '^]'.
+OK Dovecot ready. <2656.1.4d106ad9.Ovoh/[email protected]>
user oracle
+OK
pass oracle
Connection closed by foreign host.

[root@rhel6 ~]# tail -f /var/log/maillog
Dec 21 16:52:50 rhel6 dovecot: pop3-login: Login: user=<oracle>, method=PLAIN, rip=192.168.50.211, lip=192.168.50.24, mpid=9826, secured
Dec 21 16:52:50 rhel6 dovecot: pop3(oracle): Error: user oracle: Initialization failed: mail_location not set and autodetection failed: Mail storage autodetection failed with

home=/u01/oracle
Dec 21 16:52:50 rhel6 dovecot: pop3(oracle): Error: Invalid user settings. Refer to server log for more information.

設置完mail_location值後,需要重啓dovecot服務,同時需要創建相關的目錄,否則還會出現如下錯誤
freebsd# telnet 192.168.50.24 110
Trying 192.168.50.24...
Connected to 192.168.50.24.
Escape character is '^]'.
+OK Dovecot ready. <[email protected]>
user oracle
+OK
pass oracle
-ERR [IN-USE] Couldn't open INBOX: Internal error occurred. Refer to server log for more information. [2010-12-21 16:56:40]
Connection closed by foreign host.

[root@rhel6 ~]# tail -f /var/log/maillog
Dec 21 16:56:40 rhel6 dovecot: pop3-login: Login: user=<oracle>, method=PLAIN, rip=192.168.50.211, lip=192.168.50.24, mpid=10115, secured
Dec 21 16:56:41 rhel6 dovecot: pop3(oracle): Error: chown(/u01/oracle/mail/.imap/INBOX, -1, 12(mail)) failed: Operation not permitted (egid=501(dba), group based on

/var/mail/oracle)
Dec 21 16:56:41 rhel6 dovecot: pop3(oracle): Error: mkdir(/u01/oracle/mail/.imap/INBOX) failed: Operation not permitted
Dec 21 16:56:41 rhel6 dovecot: pop3(oracle): Error: Couldn't open INBOX: Internal error occurred. Refer to server log for more information. [2010-12-21 16:56:40]
Dec 21 16:56:41 rhel6 dovecot: pop3(oracle): Couldn't open INBOX top=0/0, retr=0/0, del=0/0, size=0


[root@rhel6 ~]# su - oracle
[oracle@rhel6 ~]$ mkdir -p /u01/oracle/mail/.imap/INBOX
[oracle@rhel6 ~]$ exit
logout
[root@rhel6 ~]# mail -s 'Postfix mail test'[email protected]< /etc/hosts

freebsd# telnet 192.168.50.24 110
Trying 192.168.50.24...
Connected to 192.168.50.24.
Escape character is '^]'.
+OK Dovecot ready. <2867.1.4d106ca7.L311rFiY7/[email protected]>
user oracle
+OK
pass oracle
+OK Logged in.
list
+OK 5 messages:
1 672

6:爲了使新創建的用戶可以自動創建這個目錄,可以修改/etc/skel/.bash_profile文件如下
[root@rhel6 ~]# tail -4 /etc/skel/.bash_profile

if [ ! -d ~/mail/.imap/INBOX ];then
     mkdir -p ~/mail/.imap/INBOX
fi

7:新建一個用戶,並在win7 客戶端收信測試

[root@rhel6 ~]# useradd tiger
[root@rhel6 ~]# echo '123456' |passwd --stdin tiger
更改用戶 tiger 的密碼 。
passwd: 所有的身份驗證令牌已經成功更新。
[root@rhel6 ~]# mail -s 'tiger'[email protected]< /etc/issue.net


vvvv

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章