在 CentOS 上搭建邮件服务器,常见方案是使用 Postfix(MTA)+ Dovecot(IMAP/POP3)+ 数据库/系统用户。下面给你一个从零开始的实战步骤(以 CentOS 7/8 为例,Postfix + Dovecot)。
yum update -y
邮件服务器主机名应为合法域名:
hostnamectl set-hostname mail.example.com
在你的域名解析中配置:
A记录 mail.example.com → 服务器IP
MX记录 example.com → mail.example.com
PTR记录(反向解析,找IDC申请)
yum install -y postfix dovecot cyrus-sasl
编辑配置文件:
vi /etc/postfix/main.cf
关键配置示例:
myhostname = mail.example.com
mydomain = example.com
myorigin = $mydomain
inet_interfaces = all
inet_protocols = ipv4
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
# 启用 SMTP 认证
smtpd_sasl_auth_enable = yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_security_options = noanonymous
# 限制未认证用户发信
smtpd_recipient_restrictions =
permit_sasl_authenticated,
permit_mynetworks,
reject_unauth_destination
启动 Postfix:
systemctl enable postfix
systemctl start postfix
vi /etc/dovecot/dovecot.conf
protocols = imap pop3
listen = *
vi /etc/dovecot/conf.d/10-mail.conf
mail_location = maildir:~/Maildir
vi /etc/dovecot/conf.d/10-auth.conf
disable_plaintext_auth = no
auth_mechanisms = plain login
vi /etc/dovecot/conf.d/10-master.conf
service auth {
unix_listener /var/spool/postfix/private/auth {
mode = 0660
user = postfix
group = postfix
}
}
启动 Dovecot:
systemctl enable dovecot
systemctl start dovecot
useradd -m user1
passwd user1
用户邮箱目录:
/home/user1/Maildir
firewall-cmd --permanent --add-service=smtp
firewall-cmd --permanent --add-service=pop3
firewall-cmd --permanent --add-service=imap
firewall-cmd --reload
telnet localhost 25
✅ 邮件被当成垃圾邮件?
✅ CentOS 8?
dnf 代替 yum如果你愿意,我可以:
你现在是 学习测试 还是 生产环境使用?