1.接上篇文章:安装及配置bind(DNS服务),现在来搭建一个邮件服务器
2.修改bind配置文件,添加反向代理

vi /etc/named.conf
zone "3.168.192.in-addr.arpa" IN {
    type master;
    file "192.168.3.zone";
};

3.配置解析文件

vi /var/named/192.168.3.zone
$TTL 86400
@       IN      SOA     localhost xls.com. (
                         2014031101
                         2H
                         10M
                         7D
                         1D )
                 IN      NS      localhost.
249                  IN      PTR     xls.com ;
249                IN      PTR     www.xls.com. ;

4.因Centos7自带postfix,这里只需要进行修改其配置文件即可

postconf -a#检查postfix是否支持cyrus dovecot功能,如不支持则需要安装更新的版本
vi /etc/postfix/main.cf
myhostname = mail.xls.com #为自己的主机名
mydomain = xls.com #设置本地的邮件域
myorigin = $mydomain
inet_interfaces = all #扫描监控的所有端口
inet_protocols = ipv4
mydestination = $myhostname,$mydomain #可接受邮件地址的域名
mynetworks = 0.0.0.0 #需要收发的客户端地址,这里为本地网络,只包含主机自己,可另行添加需要收发的客户端地址
home_mailbox = Maildir/ #邮件目录,在用户的home下

5.检查配置文件是否有语法错误

postfix check

6.创建邮件账号组及测试账号

groupadd mailusers #添加邮件账号组
useradd -g mailusers -s /sbin/nologin jack #创建测试账号jack
passwd jack #设置密码
useradd -g mailusers -s /sbin/nologin tom
passwd tom

7.重启postfix

systemctl restart postfix.service

8.开始测试发送邮件

[root@mail postfix]# telnet mail.xls.com 25 #连接mail服务器
Trying fe80::cead:2531:ba6b:35cf%ens33...
telnet: connect to address fe80::cead:2531:ba6b:35cf%ens33: Connection refused
Trying 192.168.3.8...
Connected to mail.xls.com.
Escape character is '^]'.
220 mail.xls.com ESMTP Postfix
helo mail.xls.com #声明本机的主机名
250 mail.xls.com
mail from:jack@xls.com #发件人
250 2.1.0 Ok
rcpt to:tom@xls.com #收件人
250 2.1.5 Ok
data #开始编辑邮件的内容
354 End data with <CR><LF>.<CR><LF>
i am xls
. #以.结尾
250 2.0.0 Ok: queued as 4D1A91184AA
quit #退出
221 2.0.0 Bye
Connection closed by foreign host.

9.查看已发送的邮件

[root@mail ~]# cat /home/tom/Maildir/new/1565704964.V803I1801d6M927346.mail.xls.com
Return-Path: <jack@xls.com>
X-Original-To: tom@xls.com
Delivered-To: tom@xls.com
Received: from mail.xls.com (xls [192.168.3.8])
        by mail.xls.com (Postfix) with SMTP id 4D1A91184AA
        for <tom@xls.com>; Tue, 13 Aug 2019 22:02:25 +0800 (CST)
 Message-Id: <20190813140236.4D1A91184AA@mail.xls.com>
Date: Tue, 13 Aug 2019 22:02:25 +0800 (CST)
From: jack@xls.com
i am xls
注:如有连接失败等报错,请在防火墙中添加允许规则

firewall-cmd --add-service=smtp --zone=home --permanent
firewall-cmd --add-port=25 --zone=home --permanent
firewall-cmd --reload