首页 > 服务器 > Linux > CentOS邮件服务器搭建系列—— POP / IMAP 服务器的构建( Dovecot )
2014
11-07

CentOS邮件服务器搭建系列—— POP / IMAP 服务器的构建( Dovecot )

前言

POP / IMAP 是 MUA 从邮件服务器中读取邮件时使用的协议。其中,与 POP3 是从邮件服务器中下载邮件比起来,IMAP 则是将邮件留在服务器端直接对邮件进行管理、操作。这里,我们用 Dovecot 来实现对 POP3 及 IMAP 等协议支持的邮件接收服务器的搭建。

Dovecot 是一个比较新的软件,由 Timo Sirainen 开发,最初发布于 2002年7月。作者将安全性考虑在第一,所以 Dovecot 在安全性方面比较出众。另外,Dovecot 支持多种认证方式,所以在功能方面也比较符合一般的应用。

安装 Dovecot

首先,安装 Dovecot 。

[root@sample ~]# yum -y install dovecot  ← 在线安装 Dovecot

Setting up Install Process
Setting up repositories
dag 100% |=========================| 1.1 kB 00:00
update 100% |=========================| 951 B 00:00
base 100% |=========================| 1.1 kB 00:00
addons 100% |=========================| 951 B 00:00
extras 100% |=========================| 1.1 kB 00:00
Reading repository metadata in from local files
Parsing package install arguments
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for dovecot to pack into transaction set.
dovecot-0.99.11-4.EL4.i38 100% |=========================| 15 kB 00:00
---> Package dovecot.i386 0:0.99.11-4.EL4 set to be updated
--> Running transaction check
--> Processing Dependency: libmysqlclient.so.14(libmysqlclient_14) for package: dovecot
--> Processing Dependency: libpq.so.3 for package: dovecot
--> Processing Dependency: libmysqlclient.so.14 for package: dovecot
--> Restarting Dependency Resolution with new changes.
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for postgresql-libs to pack into transaction set.
postgresql-libs-7.4.13-2. 100% |=========================| 11 kB 00:00
---> Package postgresql-libs.i386 0:7.4.13-2.RHEL4.1 set to be updated
---> Downloading header for mysql to pack into transaction set.
mysql-4.1.20-1.RHEL4.1.i3 100% |=========================| 35 kB 00:00
---> Package mysql.i386 0:4.1.20-1.RHEL4.1 set to be updated
--> Running transaction check
--> Processing Dependency: perl(DBI) for package: mysql
--> Restarting Dependency Resolution with new changes.
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for perl-DBI to pack into transaction set.
perl-DBI-1.40-8.i386.rpm 100% |=========================| 11 kB 00:00
---> Package perl-DBI.i386 0:1.40-8 set to be updated
--> Running transaction check
Dependencies Resolved

=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
dovecot i386 0.99.11-4.EL4 base 612 k
Installing for dependencies:
mysql i386 4.1.20-1.RHEL4.1 base 2.9 M
perl-DBI i386 1.40-8 base 466 k
postgresql-libs i386 7.4.13-2.RHEL4.1 base 146 k

Transaction Summary
=============================================================================
Install 4 Package(s)
Update 0 Package(s)
Remove 0 Package(s)
Total download size: 4.1 M
Downloading Packages:
(1/4): dovecot-0.99.11-4. 100% |=========================| 612 kB 00:00
(2/4): postgresql-libs-7. 100% |=========================| 146 kB 00:00
(3/4): mysql-4.1.20-1.RHE 100% |=========================| 2.9 MB 00:02
(4/4): perl-DBI-1.40-8.i3 100% |=========================| 466 kB 00:00
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: perl-DBI ######################### [1/4]
Installing: mysql ######################### [2/4]
Installing: postgresql-libs ######################### [3/4]
Installing: dovecot ######################### [4/4]

Installed: dovecot.i386 0:0.99.11-4.EL4
Dependency Installed: mysql.i386 0:4.1.20-1.RHEL4.1 perl-DBI.i386 0:1.40-8 postgresql-libs.i386 0:7.4.13-2.RHEL4.1
Complete!

配置 Dovecot
然后,修改相应配置文件,配置 Dovecot 。

[root@sample ~]# vi /etc/dovecot.conf  ← 编辑Dovecot 的配置文件

#protocols = imap imaps  ← 找到这一行,将协议设置为imap与pop3

protocols = imap pop3  ← 变为此状态

#default_mail_env =  ← 找到这一行,定义邮件目录

default_mail_env = maildir:~/Maildir  ← 定义邮件目录为用户目录下的Maildir目录

添加防火墙规则
由于 POP3 协议与 IMAP4 协议要分别用到110号和143号端口,所以在启动服务前,配置防火墙,开通这两个端口。

[root@sample ~]# vi /etc/sysconfig/iptables  ← 编辑防火墙规则

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 25 -j ACCEPT  ← 找到此行,接着添加如下两行:
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 110 -j ACCEPT  ← 允许POP使用的110号端口
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 143 -j ACCEPT  ← 允许IMAP使用的143号端口

[root@sample ~]# /etc/rc.d/init.d/iptables restart  ← 重新启动防火墙,使新的设置生效

Flushing firewall rules:          [ OK ]
Setting chains to policy ACCEPT: filter   [ OK ]
Unloading iptables modules:       [ OK ]
Applying iptables firewall rules:      [ OK ]

启动 Dovecot

最后,启动 Dovecot ,并将其设置为自启动。

[root@sample ~]# chkconfig dovecot on  ← 设置Dovecot为自启动

[root@sample ~]# chkconfig --list dovecot
dovecot 0:off 1:off 2:on 3:on 4:on 5:on 6:off  ← 确认2~5为on的状态就OK

[root@sample ~]# /etc/rc.d/init.d/dovecot start  ← 启动Dovecot服务

Starting Dovecot Imap:        [ OK ]

至此,配合Postfix,就可以通过E-mail客户端软件实现电子邮件的收发了。

编程技巧