RHEL6 Postfix+Dovecot邮件系统配置指南

news/2024/12/22 9:01:15/

在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   //指定允许登录的网段地址
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. <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


http://www.ppmy.cn/news/485443.html

相关文章

SVG图片绘制成不规则控件(中国省份为例)

activity_main: <?xml version"1.0" encoding"utf-8"?> <androidx.constraintlayout.widget.ConstraintLayoutxmlns:android"http://schemas.android.com/apk/res/android"xmlns:app"http://schemas.android.com/apk/res-auto&…

SVG标签属性viewbox的妙用

viewbox&#xff1a;可以根据父级大小缩放svg绘制出来的大小 <div class"h5_xp"><svg viewbox"0 0 640 640" width"100%" height"100%"><path d"M310 124 S315 140 300 134 L300 134 S294 120 310 124 L316 117 L…

python json删除字段_如何在Python中从JSON中删除括号?

我使用json.dumps将字典列表加载到JSON对象中。我的输出类似于&#xff1a;[ { "MetaData": {}, "SRData": { "ListOfLa311DeadAnimalRemoval": { "DeadAnimalRemoval": [ { "DACItemCount": "0", "DACType&…

自定义view之地图

学习目标&#xff1a; 自定义view之地图 点击边框加粗选中&#xff0c;弹出城市名字&#xff0c;重复点击会取消选中。 实现效果&#xff1a; 项目链接 学习内容&#xff1a; SVG图片 在android中我们为了使图片能在多个屏幕上适配&#xff0c;不被拉伸会使用SVG的图片。S…

java try catch 接口_Java IO 四大附加接口、try-with-resource

Java IO 四大附加接口、try-with-resource author ixenos 四大附加接口 Closeable、Flushable、Readable、Appendable Closeable&#xff1a; void close() throws IOException 关闭此流并释放与此流关联的所有系统资源 java.io.closeable扩展了java.lang.AutoCloseable&#x…

Go语言从入门到规范-6.2、Go语言os包

Go语言从入门到规范-6.2、Go语言os包 文章目录 Go语言从入门到规范-6.2、Go语言os包1.概述2.常量3.变量4.func [Chdir](https://go-zh.org/src/os/file.go?s6322:6350#L210)5.func [Chmod](https://go-zh.org/src/os/file_posix.go?s1434:1478#L48)6.func [Chown](https://go…

Pywinauto常用01--print_control_identifiers()

目录 window.print_control_identifiers()&#xff1a; 代码举例&#xff1a; 1、默认不指定参数&#xff0c;全部输出&#xff1a; 2、指定输出第2层&#xff0c;结果保存在文件output.txt中&#xff1a; window.print_control_identifiers()&#xff1a; 查看该窗口下所…

Fabric中PBFT源码解读——Checkpoint机制

文章目录 1. 写在前面1.1 前置阅读1.2 对TestCheckpoint函数的测试 2. 对TestCheckpoint函数运行流程的解读2.1 Checkpoint和Water mark的概念解释2.2 sendPrePrepare函数中对sequence的检查2.3 Commit请求时生成Checkpoint2.4 recvCheckpoint函数的实现细节&#xff08;1&…