转自:斩月 的博文
下午闲来无事,就在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/hosts192.168.50.24 rhel6.766.com rhel6127.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_64dovecot-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/postfixcommand_directory = /usr/sbindaemon_directory = /usr/libexec/postfixdata_directory = /var/lib/postfixmail_owner = postfixmydomain = rhel6.766.com //指定邮件域myorigin = $mydomaininet_interfaces = all inet_protocols = allmydestination = $myhostname, localhost.$mydomain, localhostunknown_local_recipient_reject_code = 550mynetworks_style = subnetmynetworks = 192.168.50.0/24, 127.0.0.0/8 //指定允许中继的IP地址段alias_maps = hash:/etc/aliasesalias_database = hash:/etc/aliases debug_peer_level = 2debugger_command = PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin ddd $daemon_directory/$process_name $process_id & sleep 5sendmail_path = /usr/sbin/sendmail.postfixnewaliases_path = /usr/bin/newaliases.postfixmailq_path = /usr/bin/mailq.postfixsetgid_group = postdrophtml_directory = nomanpage_directory = /usr/share/mansample_directory = /usr/share/doc/postfix-2.6.6/samplesreadme_directory = /usr/share/doc/postfix-2.6.6/README_FILES
[root@rhel6 ~]# service postfix start启动 postfix: [确定]
本地发信测试[root@rhel6 ~]# mail -s 'Postfix1' < /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 lmtplogin_trusted_networks = 192.168.50.0/24 //指定允许登录的网段地址dict { }
若未设置login_trusted_networks参数值,使用telnet登录110端口,将会出现如下错误,不知道这个值能不能设置为四个零,这个还有待测试…
freebsd# telnet 192.168.50.24 110Trying 192.168.50.24...Connected to 192.168.50.24.Escape character is '^]'.+OK Dovecot ready. <>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 outConnection closed by foreign host.
[root@rhel6 ~]# tail -f /var/log/maillogDec 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/%umbox_write_locks = fcntl
如未设置mail_location参数值,将会出现如下错误:freebsd# telnet 192.168.50.24 110Trying 192.168.50.24...Connected to 192.168.50.24.Escape character is '^]'.+OK Dovecot ready. <>user oracle+OKpass oracleConnection closed by foreign host.
[root@rhel6 ~]# tail -f /var/log/maillogDec 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, securedDec 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/oracleDec 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 110Trying 192.168.50.24...Connected to 192.168.50.24.Escape character is '^]'.+OK Dovecot ready. <>user oracle+OKpass 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/maillogDec 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, securedDec 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 permittedDec 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 ~]$ exitlogout[root@rhel6 ~]# mail -s 'Postfix mail test' < /etc/hosts
freebsd# telnet 192.168.50.24 110Trying 192.168.50.24...Connected to 192.168.50.24.Escape character is '^]'.+OK Dovecot ready. <>user oracle+OKpass 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/INBOXfi
7:新建一个用户,并在win7 客户端收信测试
[root@rhel6 ~]# useradd tiger[root@rhel6 ~]# echo '123456' |passwd --stdin tiger更改用户 tiger 的密码 。passwd: 所有的身份验证令牌已经成功更新。[root@rhel6 ~]# mail -s 'tiger' < /etc/issue.net