在CentOS系统上配置邮件服务器通常涉及以下基本步骤:
安装必要的软件包:
yum
安装Postfix(邮件传输代理MTA)、Dovecot(邮件投递代理MDA)以及相关的依赖包。sudo yum install postfix dovecot mariadb-server
配置Postfix:
/etc/postfix/main.cf
,设置以下参数:myhostname = mail.yourdomain.com
mydomain = yourdomain.com
myorigin = yourdomain.com
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
home_mailbox = Maildir/
配置Dovecot:
/etc/dovecot/dovecot.conf
,设置以下参数:protocols = imap pop3
mail_location = maildir:/Maildir
ssl = yes
ssl_cert = /etc/letsencrypt/fullchain.pem
ssl_key = /etc/letsencrypt/privkey.pem
/etc/dovecot/conf.d/10-auth.conf
,设置认证方式:auth_mechanisms = plain login
配置数据库:
sudo systemctl start mariadb
sudo mysql_secure_installation
CREATE DATABASE mail;
CREATE USER 'mail_admin'@'localhost' IDENTIFIED BY 'yourpassword';
GRANT ALL PRIVILEGES ON mail.* TO 'mail_admin'@'localhost';
FLUSH PRIVILEGES;
启动并启用服务:
sudo systemctl start postfix
sudo systemctl enable postfix
sudo systemctl start dovecot
sudo systemctl enable dovecot
配置防火墙:
firewalld
,添加允许邮件服务使用的端口:sudo firewall-cmd --permanent --add-port 25/tcp
sudo firewall-cmd --permanent --add-port 143/tcp
sudo firewall-cmd --permanent --add-port 587/tcp
sudo firewall-cmd --permanent --add-port 993/tcp
sudo firewall-cmd --reload
测试邮件服务器: