温馨提示×

centos如何安装邮件服务器

小樊
54
2026-10-08 19:44:53
栏目: 云计算

在 CentOS 上搭建邮件服务器,常见方案是使用 Postfix(MTA)+ Dovecot(IMAP/POP3)+ MariaDB/MySQL(可选用户管理)。下面以 CentOS 7/8 为例,给你一个可运行的基础邮件服务器安装教程(支持发信、收信,不含反垃圾高级配置)。


一、环境准备

# 关闭 SELinux(生产建议配置策略而非关闭)
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

# 防火墙放行端口
firewall-cmd --permanent --add-port=25/tcp
firewall-cmd --permanent --add-port=110/tcp
firewall-cmd --permanent --add-port=143/tcp
firewall-cmd --permanent --add-port=465/tcp
firewall-cmd --permanent --add-port=993/tcp
firewall-cmd --reload

⚠️ 云服务器通常封禁 25 端口,只能发信到同平台或需申请解封。


二、安装 Postfix + Dovecot

yum install -y postfix dovecot

设置 Postfix 开机启动:

systemctl enable postfix
systemctl start postfix

三、配置 Postfix(发信)

编辑配置:

vi /etc/postfix/main.cf

关键配置(示例域名 mail.example.com):

myhostname = mail.example.com
mydomain = example.com
myorigin = $mydomain
inet_interfaces = all
inet_protocols = ipv4
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
mynetworks = 127.0.0.0/8
home_mailbox = Maildir/

重启:

systemctl restart postfix

四、配置 Dovecot(收信)

vi /etc/dovecot/dovecot.conf

启用协议:

protocols = imap pop3

编辑邮箱路径:

vi /etc/dovecot/conf.d/10-mail.conf
mail_location = maildir:~/Maildir

启动 Dovecot:

systemctl enable dovecot
systemctl start dovecot

五、创建邮件用户(系统用户)

useradd -m user1
echo "password" | passwd --stdin user1

测试发送:

echo "test" | mail -s "hello" user1@example.com

查看邮件:

ls ~/user1/Maildir/new

六、DNS 配置(非常重要)

域名解析需添加:

example.com.    MX  10  mail.example.com.
mail.example.com. A  你的服务器IP

可选(推荐):

  • SPF
  • DKIM
  • DMARC

七、常见组合方案(进阶)

需求 推荐
轻量 Postfix + Dovecot
虚拟用户 Postfix + MariaDB
图形管理 iRedMail / Mailcow
企业级 Exchange(非 CentOS)

八、一键方案(新手推荐)

不想手动配置可用:

# iRedMail
bash iRedMail.sh

如果你告诉我:

  • CentOS 版本(7 / 8 / Stream)
  • 是否云服务器
  • 是否只需要发信 / 收信 / Web 邮箱

我可以给你更精确的方案。

0 踩