RHCE学习<8>Postfix+Dovecot+ExtMail构建企业邮件系统

一、电子邮件基本概念

邮件系统角色

MUA(mial user agent):使用的邮件客户端,使用IMAP或POP3协议与服务器通信。

MTA(mial transfer agent):Email的服务器端程序,通过SMTP发送、转发邮件。

MDA(mail deliver(发送) agent):将MTA接收到的邮件保存到磁盘或指定地方,通常会进行垃圾邮件及病毒扫描。

MRA(mail receive(接受) agent)负责实现IMAP与POP3协议,与MUA进行交互。

常用MUA:outlook、mac mail、mutt

常用MTA:sendmail、postfix

常用MDA:procmail、dropmail

常用MRA:dovecot

邮件系统使用协议

SMTP(simple mail transfer protocol):传输发送邮件所使用的标准协议,默认端口25。

IMAP(internet message access protocol):接受邮件使用的标准协议之一,默认端口143。

POP3(post office protocol 3):接受邮件使用的标准协议之一,默认端口110。

RHEL5默认采用sendmail做为MTA,RHEL6则采用postfix,Postfix速度比sendmail快三倍,兼容sendmail,更加稳定健壮,配置更加简单灵活,安全性较高。

#配置DNS服务器

1
2
3
[root@dns ~] # yum install gcc gcc-c++ bind bind-chroot bind-utils
[root@dns ~] # cp -r /usr/share/doc/bind-9.8.2/sample/etc/named.conf /var/named/chroot/etc/
[root@dns ~] # cp -r /usr/share/doc/bind-9.8.2/sample/var/named/* /var/named/chroot/var/named/

[root@localhost ~]# vi /var/named/chroot/etc/named.conf

204320261.jpg

[root@localhost ~]# vi /var/named/chroot/var/named/4g.com.zone

204347921.jpg

[root@localhost ~]# service named restart

客户端测试正反向解析:(DNS要指向虚拟机里的DNS服务器)

204826883.jpg

二、配置Postfix

1
2
3
4
5
6
7
8
9
[root@localhost ~] # vi /etc/postfix/main.cf  #修改如下几行,其他保持默认
myhostname = mail.4g.com     #设置postfix使用的主机名
mydomain = 4g.com            #设置postfix使用的邮件域名
myorigin = $myhostname       #外发邮件时发件人地址中的邮件域名,指明发件人所在的域名
inet_interfaces = all        #修改为监听所有IP
inet_protocols = all
mydestination = $myhostname,localhost.$mydomain, localhost, $mydomain   #允许接受哪些域名的邮件
mynetworks =192.168.1.0 /24 ,127.0.0.0 /8   #设置可转发哪些网络的邮件,这些网络的邮件可以通过MTA转发网络的任何地方
home_mailbox = Maildir/      #将一个用户的邮件统一保存在一个文件中,Maildir是用目录结构来存储邮件内容,每个邮件作为一个独立的文件,都在/home/user/Maildir/下
1
2
3
4
5
[root@localhost ~] # service postfix restart
[root@localhost ~] # chkconfig postfix on
[root@localhost ~] # netstat -tupln | grep 25  #可以看到,postfix使用的25端口
tcp        0     0 127.0.0.1:25       0.0.0.0:*                   LISTEN      1324 /master
tcp        0     0 ::1:25            :::*                        LISTEN      1324 /master

#在模板下创建邮件目录

1
2
[root@mail ~] # mkdir /etc/skel/Maildir
[root@mail ~] # chmod 700/etc/skel/Maildir/

#创建邮件用户

1
2
3
4
[root@localhost ~] # useradd user1
[root@localhost ~] # passwd user1
[root@localhost ~] # useradd user2
[root@localhost ~] # passwd user2

#测试发邮件

195741620.png

#查看user2是否收到邮件

195753238.png

三、配置Dovecot

1
2
3
4
5
6
7
8
9
10
11
[root@mail ~] # yum install dovecot –y
[root@mail ~] # vi /etc/dovecot/dovecot.conf
protocols = imap pop3 lmtp   #去掉注释
login_trusted_networks =192.168.1.0 /24   #修改只允许登陆的网段地址
[root@mail ~] # vi /etc/dovecot/conf.d/10-mail.conf
mail_location =maildir:~ /Maildir   #去掉注释
[root@mail ~] # service dovecot restart
[root@mail ~] # chkconfig dovecot on
[root@mail ~] # netstat -tupln| grep dovecot  #查看dovecot使用的110和143端口
tcp        0     0 0.0.0.0:110     0.0.0.0:*                   LISTEN      1380 /dovecot
tcp        0     0 0.0.0.0:143     0.0.0.0:*                   LISTEN      1380 /dovecot

#测试接收邮件

195900175.png

195909567.png

四、设置SMTP的用户认证

当用户通过SMTP协议向外部邮件域发送邮件时,服务器会要求用户提供用户帐号和口令进行身份认证,只有成功通过身份认证的用户才被允许向外部发送邮件,否则将拒绝发信请求。

目前,比较常用的SMTP认证机制是通过Cyrus SASL包来实现的,Cyrus SASL最大功能是为应用程序提供了认证函数库。应用程序可以通过函数库所提供的功能定义认证方式,并让SASL通过与邮件服务器主机的沟通从而提供认证的功能。

安装如下三个包:

1
2
3
4
[root@mail ~] # rpm -qa | grep cyrus
cyrus-sasl-2.1.23-13.el6_3.1.x86_64
cyrus-sasl-plain-2.1.23-13.el6_3.1.x86_64
cyrus-sasl-lib-2.1.23-13.el6_3.1.x86_64

#查看postfix是否支持cyrus的sasl认证

1
2
3
[root@mail ~] # postconf –a  #出现cyrus则支持
cyrus
dovecot
1
2
[root@mail ~] # vi /etc/sysconfig/saslauthd
MECH=shadow   #将pam改为shadow,说明从/etc/shadow检索账号
1
2
3
4
5
[root@mail ~] # service saslauthd start
[root@mail ~] # chkconfig saslauthd on
#测试下,是否能检索到账号
[root@mail ~] # testsaslauthd-u user1 -p 123.com
0: OK  "Success."

#postfix主配置文件添加SMTP认证

1
2
3
4
5
[root@mail ~] # vi/etc/postfix/main.cf   #末尾添加如下
smtpd_sasl_auth_enable= yes
smtpd_sasl_security_options=noanonymous
mynetworks=127.0.0.1
smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination

#通过命令获取到user1用户和密码加密字符串

1
2
3
4
[root@mail ~] # printf "user1" | openssl base64
dXNlcjE=
[root@mail ~] # printf "123.com" | openssl base64
MTIzLmNvbQ==

200520335.png

202011577.png

五、常用维护命令

Mailq 或 postqueue -p #查看邮件队列

postfix flush 或 postqueue -f  #重新发送队列邮件

postconf  #查看当前的有效配置

postconf  -n  #查看非默认配置

postconf  -d  #查看默认配置

postconf  -e  #修改自定义设置,如postconf  -e “inet_interfaces = all”

六、安装Extmail

ExtMail是由国内开源组织使用Perl语言开发的一套功能强大的中文Webmail平台,主要包括ExtMail、Extman两个部分的程序套件。Extmail套件用于提供从浏览器登录、使用邮件系统的Web操作界面,而Extman套件用于提供从浏览器中管理邮件系统的Web操作界面。

安装及运行ExtMail套件需要用到三个Perl支持软件包:Unix-Syslog、DBI和DBD-MySQL 依次安装这几个Perl软件包,然后将Extmail套件解压释放到Apache服务器的网页文档根目录中,并调整webmail.cf配置文件,最后再修改httpd.conf配置并重启httpd服务即可。

1.安装lamp环境

1
[root@mail ~] # yum install httpd mysql mysql-server php php-mysql -y

2.安装依赖包

1
2
3
4
5
[root@mail ~] # yum install perl-DBI perl-DBD-MySQL perl-DBIx-Simple perl-CGI perl-devel –y
[root@mail ~] # tar zxvf Unix-Syslog-1.1.tar.gz
[root@mail ~] # cd Unix-Syslog-1.1
[root@mail Unix-Syslog-1.1] # perl Makefile.PL
[root@mail Unix-Syslog-1.1] # make && make install

3.安装并配置extmail套件

1
2
3
4
[root@mail ~] # tar zxvf extmail-1.2.tar.gz
[root@mail ~] # tar zxvf extman-1.1.tar.gz
[root@mail ~] # mv extman-1.1 /var/www/extsuite
[root@mail ~] # mv extmail-1.2 /var/www/extsuite/extmail

#Apahce虚拟主机配置

1
2
3
4
5
6
7
8
9
10
11
[root@mail ~] # vi/etc/httpd/conf/httpd.conf
User postfix
Group postfix
<VirtualHost *:80>
ServerName mail.4g.com
DocumentROOT  /var/www/extsuite/extmail/html
ScriptAlias  /extmail/cgi/var/www/extsuite/extmail/cgi
Alias  /extmail/var/www/extsuite/extmail/html
ScriptAlias  /extman/cgi/var/www/extsuite/extman/cgi
Alias  /extman/var/www/extsuite/extman/html
< /VirtualHost >

#exmail配置

1
2
3
4
5
6
7
8
9
10
11
[root@mail ~] # cd /var/www/html/extmail/
[root@mail extmail] # cp webmail.cf.default webmail.cf
[root@mail extmail] # vi webmail.cf
SYS_CONFIG =  /var/www/extsuite/extmail/ #程序根目录
SYS_LANGDIR =  /var/www/extsuite/extmail/lang #语言包文件目录 SYS_TEMPLDIR = /var/www/extsuite/extmail/html     #系统模板目录 SYS_MAILDIR_BASE = /mailbox     #邮件存储目录
SYS_MYSQL_USER = root      #访问mysql数据库的用户名
SYS_MYSQL_PASS = 123.com      #访问mysql数据库的用户密码
SYS_MYSQL_DB = extmail      #使用的数据库名称
SYS_MYSQL_HOST = localhost      #mysql服务器的地址
SYS_MYSQL_SOCKET =  /var/lib/mysql/mysql .sock      #mysql套接文字位置 SYS_LDAP_BASE = o=extmailAccount,dc=extmail.org     #指定邮件域名
SYS_SHOW_SIGNUP = 1       #1为显示注册按钮,0为不显示

#extman配


1
2
3
4
5
6
7
8
9
10
[root@mail extmail] # cd../extman/
[root@mail extman] # cp webman.cf.default webman.cf
SYS_CONFIG =  /var/www/extsuite/extman/ #程序根目录
SYS_LANGDIR =  /var/www/extsuite/extman/lang #语言包文件目录 SYS_TEMPLDIR = /var/www/extsuite/extman/html     #系统模板目录 SYS_MAILDIR_BASE = /mailbox     #邮件存储目录
SYS_MYSQL_USER = root      #访问mysql数据库的用户名
SYS_MYSQL_PASS = 123.com      #访问mysql数据库的用户密码
SYS_MYSQL_DB = extmail      #使用的数据库名称
SYS_MYSQL_HOST = localhost      #mysql服务器的地址
SYS_MYSQL_SOCKET =  /var/lib/mysql/mysql .sock      #mysql套接文字位置
SYS_CAPTCHA_ON = 0        #0为关闭验证码功能,1为开启验证码功能

#导入extmail数据库

1
2
3
4
5
[root@mail docs] # service mysqld start
[root@mail docs] # mysqladmin -u root password123.com
[root@mail ~] # cd /var/www/html/extman/docs/
[root@mail docs] # mysql-uroot -p123.com < extmail.sql
[root@mail docs] # mysql-uroot -p123.com < init.sql

201720197.jpg


至此,企业级邮件系统就搭建完毕,只要域名解析MX记录,就可以在互联网发送邮件了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值