基本流程及软件版本
最近在为公司搭建私有服务器环境,调研了一些开源或付费软件,最后选择自己配置软件环境,以下为配置过程及测试。
Postfix:一种邮件传输代理软件,通常用来发送邮件;
Dovcot:邮件检索代理软件,通常用来接收邮件;
发送流程:客户端Mail Client发出邮件 —> Postfix接收,通过Dovecot进行认证(查询数据库是否存在用户) —> Dovecot把邮件存放在本地(Mail Dir)
接收流程:客户端WebMail发出获取邮件请求—> Dovecot接收请求,验证用户(查询数据库是否存在用户)—> Dovecot把邮件从本地拿出,交给客户端。
操作系统: Centos7.2
dovecot: 2.2.36 (1f10bfa63)
postfix: postfix-2.10.1-7.el7.x86_64
安装postfix
1、安装命令
yum install postfix
2、配置
文件位置: /etc/postfix/main.cf
修改内容:
#取消注释,设置hostname
myhostname = mail.domain.com
#取消注释,设置域名
mydomain = doamin.com
#99行: 取消注释
myorigin = $mydomain
#116行: 默认是localhost,我们需要修改成all
inet_interfaces = all
#119行: 推荐ipv4,如果支持ipv6,则可以为all
inet_protocols = ipv4
#164行: 添加
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
#取消注释,指定内网和本地的IP地址范围
mynetworks = 127.0.0.0/8 #也可以使用0.0.0.0/0使用所有ip及端口号
#取消注释,邮件保存目录
home_mailbox = Maildir/
#添加
smtpd_banner = $myhostname ESMTP
#添加到最后
#规定邮件最大尺寸为10M
message_size_limit = 10485760
#规定收件箱最大容量为1G
mailbox_size_limit = 1073741824
#SMTP认证
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
smtpd_recipient_restrictions = permit_mynetworks,permit_auth_destination,permit_sasl_authenticated,reject
启动postfix服务
/bin/systemctl start postfix.service
安装配置dovect
1、安装命令
yum install dovecot
2、配置
编辑文件dovecot.conf
vim /etc/dovecot/dovecot.conf
更改内容:
#26行: 如果不使用IPv6,请修改为*
listen = *
#在主配置文件中的第48行,设置允许登录的网段地址,也就是说我们可以在这里限制只有来自于某个网段的用户才能使用电子邮件系统。如果想允许所有人都能使用,则不用修改本参数
login_trusted_networks = 192.168.10.0/24更改内容
编辑文件10-auth.conf
vim /etc/dovecot/conf.d/10-auth.conf
更改内容:
# 9行: 取消注释并修改 disable_plaintext_auth = no
# 97行: 添加 auth_mechanisms = plain login
编辑文件10-mail.conf
vim /etc/dovecot/conf.d/10-mail.conf
更改内容:
# 30行: 取消注释并添加 mail_location = maildir:~/Maildir
编辑文件10-master.conf
vim /etc/dovecot/conf.d/10-master.conf
更改内容:
# 88-90行: 取消注释并添加 # Postfix smtp验证
unix_listener /var/spool/postfix/private/auth {
mode = 0666
user = postfix
group = postfix
}
注意:如果我们没有使用ssl的话需要进行下面的操作。使用了则不需要。
编辑文件10-ssl.conf
vim /etc/dovecot/conf.d/10-ssl.conf
更改内容
# 8行: 将ssl的值修改为 ssl = no
启动dovecot服务
/bin/systemctl start dovecot.service
收发邮件测试
创建用户
邮件的用户是和系统用户一致的,也就是说系统用户可以当做邮件用户。
创建用户并设置密码
useradd admin
passwd xlc123456
useradd test
passwd xlc123456
内部相互发送及接口邮件
1、admin@domain.com 发送邮件给 test@domain.com
[root@mail ~]# telnet mail.domain.com 25
Trying 47.106.14.53...
Connected to mail.domain.com.
Escape character is '^]'.
220 mail.domain.com ESMTP
mail from:admin@domain.com
250 2.1.0 Ok
rcpt to:test@domain.com
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
subject:title data 22.52
current data 22.52
.
250 2.0.0 Ok: queued as 72B6D2E4A3E
quit
221 2.0.0 Bye
Connection closed by foreign host.
2、test@domain.com接收邮件
[root@mail ~]# telnet mail.domain.com 110
Trying 47.106.14.53...
Connected to mail.domain.com.
Escape character is '^]'.
+OK Dovecot ready.
user test #用户名
+OK
pass pps123456 #密码
+OK Logged in.
list #查看邮件表列
+OK 3 messages:
1 318
2 316
3 320
.
retr 3 #查看第三封邮件
+OK 320 octets
Return-Path: <admin@domain.com>
X-Original-To: test@domain.com
Delivered-To: test@domain.com
Received: from mail.domain.com (mail.domain.com [47.106.14.53])
by mail.domain.com (Postfix) with SMTP id 72B6D2E4A3E
for <test@domain.com>; Sat, 2 Mar 2019 22:53:29 +0800 (CST)
subject:title data 22.52
current data 22.52
.
quit
+OK Logging out.
Connection closed by foreign host.
二、测试向外发送邮件
[root@mail ~]# telnet mail.doamin.com 25
Trying 47.106.14.53...
Connected to mail.doamin.com.
Escape character is '^]'.
220 mail.doamin.com ESMTP
mail from:admin@doamin.com
250 2.1.0 Ok
rcpt to:41108654488@qq.com
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
subject : title data 22.58
current data 22.58
.
250 2.0.0 Ok: queued as 9BFEB2E4A3E
quit
221 2.0.0 Bye
Connection closed by foreign host.
三、测试接收外部邮件
<发送邮件图片>
[root@mail ~]# telnet mail.doamin.com 110
Trying 47.106.14.53...
Connected to mail.doamin.com.
Escape character is '^]'.
+OK Dovecot ready.
user admin
+OK
pass pps123456
+OK Logged in.
list #查看邮件列表
+OK 5 messages:
1 308
2 310
3 319
4 2193
5 2222
.
retr 5 #查看第五封邮件内容
+OK 2222 octets
Return-Path: <41108654499@qq.com>
X-Original-To: admin@doamin.com
Delivered-To: admin@doamin.com
Received: from qq.com (smtpbg444.qq.com [183.3.255.70])
by mail.domain.com (Postfix) with ESMTP id 1D25F2E4A3E
for <admin@domain.com>; Sat, 2 Mar 2019 23:01:13 +0800 (CST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512;
t=1551538872; bh=8VMnXLV8s/vR/yNskrwsUijPh8yUrQxvgShswDZnk+Q=;
h=From:To:Subject:Mime-Version:Content-Type:Content-Transfer-Encoding:Date:Message-ID;
b=Gb/eqFRLNBmDbjWKQNvIAC5/nglqam4Mrun8CCmpM9fe7JVZRyEFr7I+pGHx65aQ8
EKU5m7KWbEq6qaEwQlz9pOVIYT2Qi1LVW5a55a19aJV4hOeY8mBXfjdUuj9N3QmIsS
q67oBpx6PXLuuvj4MLhdWEMNOEaDVViZItkoSr4A=
X-QQ-FEAT: +aXnTtpxapCdoUeeHGlPBM+1f42sdnOhpWnBk/Qur6mW/Nl3RjF2j7II3rEsa
ejy1CbWCcffVMaANUOdjP8Q9hotmWSzJEZorY5xPrWDeBgP956KqLkrYafMNClOrEV4Gm0y
GN6HQ4xA5OgxGNDjeUOcRM/CcXmbcsQ0CUnP8lk1IRxdODUqBzKUGBWpctm+8enCbQsg/FR
Q6M6hi4npvvQYXeFHqXnut0qLxgFqBkWeKqv9pyO/5BE8oR66pd3LEcp09rDxTPA=
X-QQ-SSF: 00000000000000F000000000000000Z
X-HAS-ATTACH: no
X-QQ-BUSINESS-ORIGIN: 2
X-Originating-IP: 123.98.213.202
X-QQ-STYLE:
X-QQ-mid: webmail71t1551538871t8619689
From: "=?gb18030?B?t+PStg==?=" <411086544@qq.com>
To: "=?gb18030?B?YWRtaW4=?=" <admin@domain.com>
Subject: title 23.00
Mime-Version: 1.0
Content-Type: multipart/alternative;
boundary="----=_NextPart_5C7A9AB7_0AD78F50_0D9478DF"
Content-Transfer-Encoding: 8Bit
Date: Sat, 2 Mar 2019 23:01:11 +0800
X-Priority: 3
Message-ID: <tencent_A93B01E2750309D7C20C8404525FF5665D09@qq.com>
X-QQ-MIME: TCMime 1.0 by Tencent
X-Mailer: QQMail 2.x
X-QQ-Mailer: QQMail 2.x
X-QQ-SENDSIZE: 520
Received: from qq.com (unknown [127.0.0.1])
by smtp.qq.com (ESMTP) with SMTP
id ; Sat, 02 Mar 2019 23:01:12 +0800 (CST)
Feedback-ID: webmail:qq.com:bgweb:bgweb18
This is a multi-part message in MIME format.
------=_NextPart_5C7A9AB7_0AD78F50_0D9478DF
Content-Type: text/plain;
charset="gb18030"
Content-Transfer-Encoding: base64
Y3VycmVudCAyMy4wMA==
------=_NextPart_5C7A9AB7_0AD78F50_0D9478DF
Content-Type: text/html;
charset="gb18030"
Content-Transfer-Encoding: base64
PGRpdj5jdXJyZW50IDIzLjAwPC9kaXY+
------=_NextPart_5C7A9AB7_0AD78F50_0D9478DF--
.