The best life is use of willing attitude, a happy-go-lucky life.
— Mr.Wang
发布时间:2016-07-28 08:36:10
发布作者:admin
4912
在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'ylw6006@163.com< /etc/hosts
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 //指定允许登录的网段地址
disable_plaintext_auth = no //有就把这个改成no ,没有就添加这句
dict {
}
修改 /etc/dovecot/conf.d/10-mail.conf 去掉 mail_location = mbox:~/mail:INBOX=/var/mail/%u前面的#号,重启dovecot。
若未设置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. <2564.2.4d106a4d.NTUFLnbszkRtt73yHZq2iw==@rhel6.766.com>
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/mkl1gK+XPX5qohEbA==@rhel6.766.com>
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. <2781.1.4d106bc3.JFuUEG+bO68ixpY2W1zihg==@rhel6.766.com>
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'oracle@rhel6.766.com< /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/LIWOTM2Cp3Xg==@rhel6.766.com>
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'tiger@rhel6.766.com< /etc/issue.net