centos

如何在CentOS上部署邮件服务器

小樊
49
2025-03-11 17:16:32
栏目: 云计算

在CentOS上部署邮件服务器是一个复杂但非常有意义的任务,以下是详细的步骤和注意事项:

基础环境准备

安装邮件服务

  1. 更新系统
sudo yum update -y
  1. 安装必要的软件包
sudo yum install postfix dovecot mariadb-server mariadb -y
  1. 配置MySQL
sudo mysql_secure_installation
sudo mysql -u root -p
CREATE DATABASE mail;
USE mail;
CREATE TABLE users (id INT AUTO_INCREMENT PRIMARY KEY, email VARCHAR(255) NOT NULL, password VARCHAR(255) NOT NULL);
GRANT SELECT, INSERT, UPDATE, DELETE ON mail.* TO 'mailuser'@'localhost' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
EXIT;
  1. 配置Postfix
myhostname mail.example.com
mydomain example.com
myorigin mydomain
inet_interfaces all
inet_protocols ipv4
mydestination myhostname, localhost.mydomain, localhost, mydomain
home_mailbox Maildir/
smtpd_banner myhostname ESMTP
smtpd_recipient_restrictions permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
smtpd_sasl_auth_enable yes
smtpd_sasl_security_options noanonymous
smtpd_sasl_type dovecot
smtpd_sasl_path private/auth
smtpd_sasl_local_domain myhostname
sudo systemctl start postfix
sudo systemctl enable postfix
  1. 配置Dovecot
protocols imap pop3
mail_location maildir:/Maildir
mail_location maildir:/Maildir
sudo systemctl start dovecot
sudo systemctl enable dovecot
  1. 配置防火墙
sudo firewall-cmd --permanent --add-services=smtp
sudo firewall-cmd --permanent --add-service=pop3
sudo firewall-cmd --permanent --add-service=imap
sudo firewall-cmd --reload
  1. 配置RoundCube(可选):
wget https://github.com/roundcube/roundcube/releases/download/v1.3.12/roundcube-1.3.12.tar.gz
tar xvf roundcube-1.3.12.tar.gz
cd roundcube-1.3.12
./configure
make
sudo make install
sudo cp config/config.inc.php.sample config/config.inc.php

测试邮件服务器

  1. 查看端口监听状态
netstat -ntlp | grep :25
netstat -ntlp | grep :110
  1. 使用邮件客户端测试

常见问题及解答

message_size_limit 10485760 # 例如10MB

然后重启Postfix服务以使更改生效。

0
看了该问题的人还看了