搭建邮件服务器 Postfix + Dovecot (CentOS)

最近分配到一台ECS服务器,需要搭建一台邮件服务器。

查了一波资料选择了Postfix (smtp)和 Dovecot(pop3).

推荐教程:http://www.cnblogs.com/zlbeidou/p/3436332.html (我的是CentOS6.5 如果是Centos7.*的注意selinux,防止出现坑,ubuntu用此教程的话注意使用sudo指令,其他基本相同)

1:配置 DNS 服务器并添加邮件服务器 MX 记录. 并让 ISP 支持你的静态 IP 与域名. (局域网搭建跳过此步骤,服务器必须)

2:安装 Postfix

[root@server ~]# yum install postfix -y

配置 Postfix

打开 /etc/postfix/main.cf 更改如下配置:

## Line no  - Uncomment and set your mail server FQDN ##
myhostname = server.cnblogs.com 你的主机名称(比我是mail.xxx.com,需要加到MX记录,优先级10) ## Line - Uncomment and Set domain name ##
mydomain = cnblogs.com 你的域名(比如我是xxx.com) ## Line - Uncomment ##
myorigin = $mydomain ## Line - Set ipv4 ##
inet_interfaces = all ## Line - Change to all ##
inet_protocols = all ## Line - Comment ## #mydestination = $myhostname, localhost.$mydomain, localhost, ## Line - Uncomment ##
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain ## Line - Uncomment and add IP range ##
mynetworks = 192.168.1.0/, 127.0.0.0/8(也可以不改) ## Line - Uncomment ##
home_mailbox = Maildir/ (邮件存放目录)

保存并退出, 重启 Postfix 服务:

[root@server ~]# /etc/init.d/postfix start
[root@server ~]# /etc/init.d/postfix status
master (pid ) is running...
[root@server ~]# chkconfig postfix on

测试 Postfix

通过 telnet 进行测试, 没有 telnet 可通过 yum 安装, 一下出现红色字体表示输入.

新建测试用户 fourone:

[root@server ~]# useradd fourone
[root@server ~]# passwd fourone

测试功能

[root@server ~]# telnet localhost smtp
Trying ::...
Connected to localhost.
Escape character is '^]'.
server.cnblogs.com ESMTP Postfix
ehlo localhost
-server.cnblogs.com
-PIPELINING
-SIZE
-VRFY
-ETRN
-ENHANCEDSTATUSCODES
-8BITMIME
DSN
mail from:<fourone>
2.1. Ok
rcpt to:<fourone>
2.1. Ok
data
End data with <CR><LF>.<CR><LF>
hello fourone
.
2.0. Ok: queued as 3E68E284C
quit
2.0. Bye
Connection closed by foreign host.

进入 fourone mail 目录检查邮件:

[root@server ~]# ls /home/fourone/Maildir/new/
.Vfd00I41ec0M251771.server.cnblogs.com
[root@server ~]# cat /home/fourone/Maildir/new/.Vfd00I41ec0M251771.server.cnblogs.com
Return-Path: <fourone@cnblogs.com>
X-Original-To: fourone
Delivered-To: fourone@cnblogs.com
Received: from localhost (localhost [IPv6:::])
by server.cnblogs.com (Postfix) with ESMTP id 3E68E284C
for <zl>; Wed, May :: + (IST)
Message-Id: <.3E68E284C@server.cnblogs.com>
Date: Wed, May :: + (IST)
From: fourone@cnblogs.com
To: undisclosed-recipients:;
hello fourone
 

3:安装 Dovecot

Dovecote 是一款开源 IMAP/POP3 邮件服务器 for Unix/Linux systems.

[root@server ~]# yum install dovecot

配置 Dovecot

打开 /etc/dovecot/dovecot.conf 更改如下配置:

## Line  - umcomment ##
protocols = imap pop3 lmtp

打开 /etc/dovecot/conf.d/10-mail.conf:

## Line  - uncomment ##
mail_location = maildir:~/Maildir (遇上面postfix一致)

打开 /etc/dovecot/conf.d/10-auth.conf:

## line  - uncomment##
disable_plaintext_auth = yes (出现如果不要ssl验证的则是no) ## Line - Add a letter "login" ##
auth_mechanisms = plain login

打开 /etc/dovecot/conf.d/10-master.conf:

## Line ,  - Uncomment and add "postfix"
#mode =
user = postfix
group = postfix

开启 Dovecot 服务:

[root@server ~]# service dovecot start
Starting Dovecot Imap: [ OK ]
[root@server ~]# chkconfig dovecot on (加入系统启动项)

测试 Dovecot

[root@server ~]# telnet localhost pop3
Trying ::...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
user fourone
+OK
pass ## Here is password of user "fourone" ##
+OK Logged in.
list
+OK messages: .
retr
+OK octets
Return-Path: <fourone@cnblogs.com>
X-Original-To: fourone
Delivered-To: fourone@cnblogs.com
Received: from localhost (localhost [IPv6:::])
by server.cnblogs.com (Postfix) with ESMTP id 3E68E284C
for <zl>; Wed, May :: + (IST)
Message-Id: <.3E68E284C@server.cnblogs.com>
Date: Wed, May :: + (IST)
From: fourone@cnblogs.com
To: undisclosed-recipients:; hello fourone
.
quit
+OK Logging out.
Connection closed by foreign host.

Dovecot 测试成功.

上一篇:barrel_shift


下一篇:Linux搭建邮件服务器Postfix+Dovecot+MySQL+PHP