一、目标

在centos7搭建邮件服务器postfix版。(无坑版)

二、平台

centos7.6,postfix-2.10.1-7.el7.x86_64

三、解析

1.
2.

四、Postfix邮件服务器设置

1.基本配置

systemctl stop firewalld
systemctl disable firewalld
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0

2.修改主机名

hostnamectl set-hostname mail.hiibm.com

3.修改默认邮件传输代理为MTA(执行下面的命令后,紧跟着一个回车继续即可)

alternatives --config mta

4.验证MTA状态(查出值的话基本上说明就没问题)

alternatives --display mta |grep "status is manual" && echo -e "\e[1;32mOK\e[0m" || echo -e "\e[1;31mNotOK\e[0m"

5.安装postfix

rpm -qa |grep postfix || yum install -y postfix

6.修改postfix主配置文件(一大坨部分,只需要去掉#号开头的注释行后,复制所有粘贴执行,不过还得修改你所在的网段和域名等相关信息后再执行)

cp /etc/postfix/main.cf{,.bak}
#1.设定邮箱域名
sed -i 's/#myhostname = host.domain.tld/myhostname = mail.hiibm.com/' /etc/postfix/main.cf
#2.设定邮箱的域
sed -i 's/#mydomain = domain.tld/mydomain = hiibm.com/' /etc/postfix/main.cf
#3.设定邮箱的域
sed -i 's/#myorigin = $mydomain/myorigin = $mydomain/' /etc/postfix/main.cf
#4.设定邮箱支持网络协议为ipv4(本步可略,略过的话就支持ipv4和ipv6)
sed -i 's/inet_protocols = all/inet_protocols = ipv4/' /etc/postfix/main.cf
#5.设定网络接口
sed -i 's/inet_interfaces = localhost/inet_interfaces = all/' /etc/postfix/main.cf
#6.设定域名
sed -i 's/mydestination = $myhostname, localhost.$mydomain, localhost/mydestination = $myhostname, localhost.$mydomain, localhost, \$mydomain/' /etc/postfix/main.cf
#7.设定postfix支持的网段
sed -i "s@#mynetworks = 168.100.189.0/28, 127.0.0.0/8@mynetworks = 192.168.0.0/24, 127.0.0.0/8@" /etc/postfix/main.cf
#设定邮箱用户收到的邮件存放的目录(即各邮箱用户的家目录下的Maildir目录下存手来的邮件)
sed -i "s@#home_mailbox = Maildir/@home_mailbox = Maildir/@" /etc/postfix/main.cf
#在第571行处增加banner
sed -i '571c smtpd_banner = \$myhostname ESMTP' /etc/postfix/main.cf
#指定收邮件用dovecot,并设置禁用匿名登录
cat >> /etc/postfix/main.cf <<EOF
message_size_limit = 10485760
mailbox_size_limit = 1073741824
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
EOF

7.重启postfix服务

systemctl restart postfix
systemctl enable postfix

8.安装dovecot

rpm -qa |grep dovecot || yum install -y dovecot

9.修改dovecot的几个配置文件

cp /etc/dovecot/dovecot.conf{,.bak}
cp /etc/dovecot/conf.d/10-auth.conf{,.bak}
cp /etc/dovecot/conf.d/10-mail.conf{,.bak}
cp /etc/dovecot/conf.d/10-master.conf{,.bak}
cp /etc/dovecot/conf.d/10-ssl.conf{,.bak}
#1.修改dovecot仅支持ipv4协议
sed -i 's/#listen = \*, ::/listen = \*/' /etc/dovecot/dovecot.conf
#2.
sed -i 's/#disable_plaintext_auth = yes/disable_plaintext_auth = no/' /etc/dovecot/conf.d/10-auth.conf
$3.
sed -i 's/auth_mechanisms = plain/auth_mechanisms = plain login/' /etc/dovecot/conf.d/10-auth.conf
#4.
sed -i "s@#mail_location =@mail_location = maildir:~/Maildir@" /etc/dovecot/conf.d/10-mail.conf

10.修改/etc/dovecot/conf.d/10-master.conf的第96-98行
修改
#unix_listener /var/spool/postfix/private/auth {
    #  mode = 0666
    #}
修改为

  unix_listener /var/spool/postfix/private/auth {
    mode = 0666
    user = postfix
    group = postfix
  }

11.注意:如果我们没有使用ssl的话需要进行下面的操作。使用了则不需要。

sed -i 's/ssl = required/ssl = no/' /etc/dovecot/conf.d/10-ssl.conf

12.启动dovecot

systemctl restart dovecot
systemctl enable dovecot

五、给Postfix添加邮箱用户

groupadd xmailusers
useradd -g xmailusers -s /sbin/nologin xmail1
useradd -g xmailusers -s /sbin/nologin xmail2
echo "A@#$123456" |passwd --stdin xmail1
echo "A@#$123456" |passwd --stdin xmail2

六、使用telnet验证邮件收发

1.安装telnet工具

rpm -qa |grep telnet ||yum install -y telnet

2.centos下使用telnet验证发送邮件

telnet 127.0.0.1 25
helo mail.hiibm.com
mail from:xmail1@hiibm.com
rcpt to:xmail2@hiibm.com
data
i am xmail1,nihaoa
.
quit

3.在centos命令行模式下查看postfix邮件

#xmail2是之前创建的几个centos账号之一,一个邮件就是一个文件
cat /home/xmail2/Maildir/new/随机数字.随机字符.mail.hiibm.com

七、使用outlook测试邮件收发

1.

2.

3.

4.

5.

测试没问题。老铁双击666

----------------------END---------2020年4月7日13:53:00-----------------------

参考文档1:https://www.cnblogs.com/operationhome/p/9056870.html
参考文档2:https://blog.51cto.com/12227558/2074095

GitHub 加速计划 / li / linux-dash
10.39 K
1.2 K
下载
A beautiful web dashboard for Linux
最近提交(Master分支:2 个月前 )
186a802e added ecosystem file for PM2 4 年前
5def40a3 Add host customization support for the NodeJS version 4 年前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐