CentOS下使用Postfix收发信 目标直接在服务器上使用 Postfix 收发信并非使用 Foxmail 等客户端。环境域名一个假设为yourdomain.com。服务器一台CentOS 7.9Postfix 2.10.1配置域名解析添加 A 记录主机记录为 mail记录值为服务器的公网 IP此处假设为12.34.56.78。添加 MX 记录主机记录为 记录值为mail.yourdomain.com。配置服务器使用以下命令修改 hostname。hostnamectl set-hostname mail.yourdomain.com配置PostfixCentOS 7.9 自带 Postfix使用以下命令查看版本。postconf mail_version使用以下命令启动 Postfix。systemctl start postfix使用以下命令使 Postfix 开机自启。systemctl enable postfix使用以下命令查看 Postfix 的状态。systemctl status postfix看到 enabled 和 active 即可。使用以下命令配置 Postfix具体意义自行查询。postconf -e inet_interfaces all postconf -e myhostname mail.yourdomain.com postconf -e myorigin yourdomain.com postconf -e mydestination yourdomain.com, \$myhostname, localhost.\$mydomain, localhost使用以下命令重启 Postfix。systemctl restart postfix使用以下命令打开 25 端口TCP。firewall-cmd --permanent --add-port25/tcp运行后输出FirewallD is not running因为本来防火墙就没开此处不讨论这个问题。可以使用网上的 TCP Port Scanner 来检测上述 25 端口是否打开非必须。使用以下命令安装 Telnet。yum install -y telnet使用以下命令测试上述 25 端口是否能向外导通。telnet gmail-smtp-in.l.google.com 25输出应该与如下内容相似。Trying 55.66.77.88... Connected to gmail-smtp-in.l.google.com. Escape character is ^]. 220 mx.google.com ESMTP d9685215c04436cbebdsi42-1fed7f1a733ad.514 - gsmtp如果失败会显示 Connection timed out 等。某些云服务器的 25 端口不能向外导通华为云可以。输入 quit 然后回车进行退出。测试使用以下命令测试发信功能。echo test email | sendmail xxooqq.com使用以下命令测试收信功能(输入之后按数字键来打开对应的邮件)。mail原文链接https://www.linuxbabe.com/redhat/run-your-own-email-server-centos-postfix-smtp-server