使用 Postfix、Dovecot、MySQL 和 RoundCube 在 Rock Linux 8 上设置邮件服务器 |使用 Postfix、Dovecot、MySQL 和 RoundCube 在 Rock Linux 8 上设置邮件服务器 |使用 Postfix、Dovecot、MySQL 和 RoundCube 在 Rock Linux 8 上设置邮件服务器 |使用 Postfix、Dovecot、MySQL 和 RoundCube 在 Rock Linux 8 上设置邮件服务器 |
  • 业务
  • 目标
  • 支持
  • 登录
找到的结果: {phrase} (显示: {results_count} 共: {results_count_total})
显示: {results_count} 共: {results_count_total}

加载更多搜索结果...

搜索范围
模糊匹配
搜索标题
搜索内容

使用 Postfix、Dovecot、MySQL 和 RoundCube 在 Rock Linux 8 上设置邮件服务器 |

发表 admin at 2025年2月28日
类别
  • 未分类
标签
コアサーバーV2プランご契約でドメイン更新費用が永久無料

邮件服务器或邮件传输代理(MTA) 是一种从本地或远程发件人接收电子邮件并将传出邮件转发到所需服务器的应用程序。发送电子邮件时,它会经过一系列服务器才能到达最终目的地。这个过程非常快,您可能无法意识到发送和接收电子邮件背后的复杂性。

下面是电子邮件服务器如何工作的图示。

根据所使用的协议,邮件服务器分为两大类:

  • 发送邮件服务器:它们使用 SMTP 协议。

    • SMTP(简单邮件传输协议):此协议处理任何外发邮件请求并发送电子邮件。
  • 传入邮件服务器:它们进一步分为两部分:

    • POP3(邮局协议,版本 3):它们将发送和接收的消息存储在本地存储中
    • IMAP(互联网消息访问协议):它们通过同步整个邮箱在服务器上存储发送和接收消息的副本

在本教程中,您将学习如何使用 Postfix、Dovecot、MySQL 和 RoundCube 在 Rock Linux 8 上设置邮件服务器。本指南使用 Postfix 作为 SMTP 服务器,使用 Dovecot 提供 POP/IMAP 功能,并使用 RoundCube 作为网络邮件程序或客户端,允许用户从浏览器发送和接收电子邮件。

为了获得清晰的概述,下面详细解释了此处使用的所有组件:

  • Postfix:这是一个免费的开源邮件传输代理 (MTA),用于通过互联网在服务器之间中继电子邮件。 Postfix 具有高度可配置性和极大的灵活性。
  • Dovecot:这是一个用于类似 Linux/UNIX 系统的开源 IMAP 和 POP3 电子邮件服务器,在编写时主要考虑到安全性。它充当本地投递代理 (LDA),从 Postfix 或其他 MTA/邮件服务器软件获取电子邮件并存储它们。
  • Roundcube:大多数用户需要一个易于使用的界面来阅读发送后的电子邮件。 Roundcube 是此任务的首选选项之一。它是一个基于浏览器的多语言 IMAP 客户端,具有类似应用程序的用户界面,可提供您期望从电子邮件客户端获得的全部功能。这包括地址簿、文件夹操作、拼写检查、消息搜索和 MIME 支持。

入门

本指南要求您具备以下条件:

  • 完全合格的域名
  • 在公共域名服务器中为您的域创建 A 和 MX 记录

更新您的系统并设置主机名;

sudo dnf update -y
sudo hostnamectl set-hostname mail.example.com

您还需要禁用 SELinux:

sudo sed -i 's/^SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
sudo reboot

第 1 步 – 安装所需的软件包

我们将首先在 Rocky Linux 8 上安装 Postfix(邮件传输代理)、Apache 和 PHP 软件包。

sudo yum install epel-release -y
sudo dnf install wget postfix certbot postfix-mysql httpd vim policycoreutils-python-utils -y

Roundcube 需要 PHP 7.3 及以上版本才能显示网页。启用 Remi 存储库;

sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm 

列出可用的 PHP 版本;

$ sudo dnf module list php
Last metadata expiration check: 0:00:01 ago on Sat 01 Oct 2022 09:27:43 UTC.
Rocky Linux 8 - AppStream
Name     Stream         Profiles                       Summary                  
php      7.2 [d][e]     common [d], devel, minimal     PHP scripting language   
php      7.3            common [d], devel, minimal     PHP scripting language   
php      7.4            common [d], devel, minimal     PHP scripting language   
php      8.0            common [d], devel, minimal     PHP scripting language   

Remi's Modular repository for Enterprise Linux 8 - x86_64
Name     Stream         Profiles                       Summary                  
php      remi-7.2       common [d], devel, minimal     PHP scripting language   
php      remi-7.3       common [d], devel, minimal     PHP scripting language   
php      remi-7.4       common [d], devel, minimal     PHP scripting language   
php      remi-8.0       common [d], devel, minimal     PHP scripting language   
php      remi-8.1       common [d], devel, minimal     PHP scripting language   
php      remi-8.2       common [d], devel, minimal     PHP scripting language   

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

启用首选版本,例如 PHP 8.0:

sudo dnf module -y reset php
sudo dnf module enable php:remi-8.0 -y

现在使用以下命令安装 PHP 和所有必需的模块:

sudo yum install php-{pear,cgi,common,curl,gmp,fpm,mbstring,gd,mysqli,gettext,bcmath,json,xml,fpm,intl,zip} -y

完成后,检查安装的版本。

$ php --version
PHP 8.0.24 (cli) (built: Sep 28 2022 15:32:34) ( NTS gcc x86_64 )
Copyright (c) The PHP Group
Zend Engine v4.0.24, Copyright (c) Zend Technologies

步骤 2 – 为域名安装 SSL 证书

我们将首先为 FQDN 安装 SSL 证书。在本指南中,我们将使用 Let’sEncrypt 颁发免费的可信 SSL 证书。让我们从安装 certbot 工具开始。

# Ubuntu / Debian
sudo apt update
sudo apt install certbot

# Fedora
sudo dnf install certbot

# RHEL 8 based systems
sudo dnf -y install epel-release
sudo yum -y install certbot

# CentOS 7
sudo yum -y install epel-release
sudo yum -y install certbot

确保安装了所需的包:

$ certbot --version
certbot 1.22.0

现在安装 SSL 证书

sudo certbot certonly --standalone

如图所示继续操作,并将 mail.example.com 替换为您服务器的正确 FQDN

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Enter email address (used for urgent renewal and security notices)
 (Enter 'c' to cancel): [email 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.3-September-21-2022.pdf. You must
agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: y

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, to
share your email address with the Electronic Frontier Foundation, a founding
partner of the Let's Encrypt project and the non-profit organization that
develops Certbot? We'd like to send you email about our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: y
Account registered.
Please enter the domain name(s) you would like on your certificate (comma and/or
space separated) (Enter 'c' to cancel): mail.example.com
Requesting a certificate for mail.example.com

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/mail.example.com/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/mail.example.com/privkey.pem
This certificate expires on 2022-12-30.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.

创建证书目录;

sudo mkdir /etc/postfix/ssl
sudo chmod -R 775 /etc/postfix/ssl

将创建的证书复制到目录:

sudo cp /etc/letsencrypt/live/mail.example.com/fullchain.pem /etc/postfix/ssl
sudo cp /etc/letsencrypt/live/mail.example.com/privkey.pem /etc/postfix/ssl

步骤 3 – 安装和配置数据库

我们需要一个数据库(MYSQL 或其分支 MariaDB)来存储和检索 Roundcube 和 Postfix 的重要数据。

可以使用以下命令从默认的 Rocky Linux 8 存储库安装 MariaDB:

sudo dnf install mariadb-server mariadb

安装后,启动并启用该服务:

sudo systemctl enable --now mariadb

强化 MariaDB 实例:

$ sudo mysql_secure_installation
....
Enter current password for root (enter for none): Just press Enter
......
Switch to unix_socket authentication [Y/n] Y
.....
Change the root password? [Y/n] Y
New password:  New-root-password
Re-enter new password: Re-enter New-root-password
....
Remove anonymous users? [Y/n] Y
....
Disallow root login remotely? [Y/n] Y
.....
Remove test database and access to it? [Y/n] Y
......
Reload privilege tables now? [Y/n] Y
...
Thanks for using MariaDB!

使用设置的密码登录 MariaDB shell:

mysql -u root -p

现在创建 Postfix 邮件帐户数据库。

create database postfix_accounts;
grant all on postfix_accounts.* to postfix_admin@localhost identified by 'StrongPassw0rd';
flush privileges;

现在创建用于存储域的表:

CREATE TABLE `postfix_accounts`.`domains_table` ( `DomainId` INT NOT NULL AUTO_INCREMENT , `DomainName` VARCHAR(50) NOT NULL , PRIMARY KEY (`DomainId`)) ENGINE = InnoDB;

另外,在数据库中创建表来存储用户帐户。

CREATE TABLE `postfix_accounts`.`accounts_table` ( 
    `AccountId` INT NOT NULL AUTO_INCREMENT,  
    `DomainId` INT NOT NULL,  
    `password` VARCHAR(300) NOT NULL,  
    `Email` VARCHAR(100) NOT NULL,  
    PRIMARY KEY (`AccountId`),  
    UNIQUE KEY `Email` (`Email`),  
    FOREIGN KEY (DomainId) REFERENCES domains_table(DomainId) ON DELETE CASCADE 
) ENGINE = InnoDB;

创建一个表来存储电子邮件别名数据。

CREATE TABLE `postfix_accounts`.`alias_table` (
    `AliasId` INT NOT NULL AUTO_INCREMENT, 
    `DomainId` INT NOT NULL, 
    `Source` varchar(100) NOT NULL, 
    `Destination` varchar(100) NOT NULL, 
    PRIMARY KEY (`AliasId`), 
    FOREIGN KEY (DomainId) REFERENCES domains_table(DomainId) ON DELETE CASCADE
) ENGINE = InnoDB;

我们将向创建的表添加记录。为了演示,我将添加一些帐户和别名。

INSERT INTO `postfix_accounts`.`domains_table` (DomainName) VALUES ('example.com');  
INSERT INTO `postfix_accounts`.`accounts_table` (DomainId, password, Email) VALUES (1, ENCRYPT('Password', CONCAT('$6$', SUBSTRING(SHA(RAND()), -16))), '[email ');  
INSERT INTO `postfix_accounts`.`accounts_table` (DomainId, password, Email) VALUES (1, ENCRYPT('Password', CONCAT('$6$', SUBSTRING(SHA(RAND()), -16))), '[email ');  
INSERT INTO `postfix_accounts`.`alias_table` (DomainId, Source, Destination) VALUES (1, '[email ', '[email ');

您可以使用您的 win 用户名和密码作为 postfix_admin 用户 和 postfix_accounts 数据库 名称。

另外,为 Roundcube 创建一个数据库:

create database roundcube;
grant all on roundcube.* to roundcube_admin@localhost identified by 'StrongPassw0rd';
flush privileges;
quit;

步骤 4 – 在 Rocky Linux 8 上配置 Postfix MTA

我们现在需要配置 Postfix MTA 以便能够发送和接收电子邮件。默认配置文件位于/etc/postfix

打开主配置文件进行编辑;

sudo vim /etc/postfix/master.cf

在文件中,您需要取消注释以下行并确保保留缩进。

......
submission inet n       -       n       -       -       smtpd
  -o syslog_name=postfix/submission
  -o smtpd_tls_security_level=encrypt   ## Comment this if you have no SSL(not recommended)
  -o smtpd_tls_auth_only=yes            ## Comment this if you have no SSL(not recommended)
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject
  -o milter_macro_daemon_name=ORIGINATING
  -o smtpd_reject_unlisted_recipient=no
....

在文件底部,添加以下与 dovecot 相关的配置:

dovecot   unix  -       n       n       -       -       pipe
    flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}

保存文件并打开主 Postfix 配置:

sudo vim /etc/postfix/main.cf

在此文件中,您需要进行多项配置,包括:

  • 主机名
myhostname = mail.example.com
  • 域名
mydomain = example.com   ## Input your unique domain here

另外,取消注释以下行:

myorigin = $myhostname
inet_interfaces = all
inet_protocols = all
mydestination = $myhostname, localhost.$mydomain, localhost
smtpd_recipient_restrictions = permit_mynetworks
home_mailbox = Maildir/

在同一文件中,添加以下行。有些行定义 SSL 证书文件,您可能需要将其复制到指定路径。如果您没有 SSL 证书,请注释掉特定行:

append_dot_mydomain = no
biff = no
config_directory = /etc/postfix
dovecot_destination_recipient_limit = 1
message_size_limit = 4194304
smtpd_tls_cert_file = /etc/postfix/ssl/fullchain.pem  ##SSL Cert
smtpd_tls_key_file = /etc/postfix/ssl/privkey.pem       ##SSL Key
smtpd_use_tls=yes
smtpd_tls_security_level = may

smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
virtual_transport = dovecot
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth

要授予 Postfix 访问数据库中存储的帐户相关数据的权限,请添加以下行:

virtual_mailbox_domains = mysql:/etc/postfix/database-domains.cf
virtual_mailbox_maps = mysql:/etc/postfix/database-users.cf
virtual_alias_maps = mysql:/etc/postfix/database-alias.cf

保存文件并打开另一个配置文件来定义域的数据库详细信息:

sudo vim /etc/postfix/database-domains.cf

在文件中,提供数据库凭据;

user = postfix_admin
password = StrongPassw0rd
hosts = 127.0.0.1
dbname = postfix_accounts
query = SELECT 1 FROM domains_table WHERE DomainName='%s'

对于用户帐户:

sudo vim /etc/postfix/database-users.cf

添加以下行:

user = postfix_admin
password = StrongPassw0rd
hosts = 127.0.0.1
dbname = postfix_accounts
query = SELECT 1 FROM accounts_table WHERE Email='%s'

对于电子邮件别名:

sudo vim /etc/postfix/database-alias.cf

添加以下行:

user = postfix_admin
password = StrongPassw0rd
hosts = 127.0.0.1
dbname = postfix_accounts
query = SELECT Destination FROM alias_table WHERE Source='%s'

现在设置创建的文件的权限:

sudo chmod 640 /etc/postfix/database-domains.cf
sudo chmod 640 /etc/postfix/database-users.cf
sudo chmod 640 /etc/postfix/database-alias.cf

设置所有权:

sudo chown root:postfix /etc/postfix/database-domains.cf
sudo chown root:postfix /etc/postfix/database-users.cf
sudo chown root:postfix /etc/postfix/database-alias.cf

要应用所做的更改,请重新启动 Postfix:

sudo systemctl restart postfix

检查服务的状态:

$ systemctl status postfix
● postfix.service - Postfix Mail Transport Agent
   Loaded: loaded (/usr/lib/systemd/system/postfix.service; disabled; vendor preset: disabled)
   Active: active (running) since Sun 2022-10-02 08:32:28 UTC; 11s ago
  Process: 6763 ExecStart=/usr/sbin/postfix start (code=exited, status=0/SUCCESS)
  Process: 6761 ExecStartPre=/usr/libexec/postfix/chroot-update (code=exited, status=0/SUCCESS)
  Process: 6755 ExecStartPre=/usr/libexec/postfix/aliasesdb (code=exited, status=0/SUCCESS)
  Process: 6753 ExecStartPre=/usr/sbin/restorecon -R /var/spool/postfix/pid/master.pid (code=exited, status=0/SUCCESS)
 Main PID: 6831 (master)
    Tasks: 3 (limit: 48239)
   Memory: 4.8M
   CGroup: /system.slice/postfix.service
           ├─6831 /usr/libexec/postfix/master -w
           ├─6832 pickup -l -t unix -u
           └─6833 qmgr -l -t unix -u

在继续之前,让我们测试一下 Postfix 是否按预期工作。如果成功,我们应该会看到 1,或者最后一个的电子邮件地址。

sudo postmap -q example.com mysql:/etc/postfix/database-domains.cf
sudo postmap -q [email  mysql:/etc/postfix/database-users.cf
sudo postmap -q [email  mysql:/etc/postfix/database-users.cf
sudo postmap -q [email  mysql:/etc/postfix/database-alias.cf

步骤 5 – 在 Rocky Linux 8 上安装和配置 Dovecot

Dovecot 将用作开源 IMAP 和 POP3 电子邮件服务器。这些协议用于将电子邮件从服务器发送到本地计算机。

要安装 Dovecot,请使用以下命令:

sudo dnf install dovecot dovecot-mysql -y

完成后,添加用户和组来处理邮件;

sudo groupadd -g 6000 vmail 
sudo useradd -g vmail -u 6000 vmail -d /home/vmail -m

我们现在开始配置。这里有相当多的配置需要进行。

让我们从主配置文件开始。

$ sudo vim /etc/dovecot/dovecot.conf
protocols = imap pop3 lmtp
listen = *, ::
!include conf.d/*.conf
!include_try local.conf
log_path = /var/log/dovecot.log  ##Add this for logs

创建具有所需权限的日志路径;

sudo touch /var/log/dovecot.log
sudo chmod 775 /var/log/dovecot.log

接下来,编辑以下文件并注释以下行;

$ sudo vim /etc/dovecot/conf.d/10-auth.conf
disable_plaintext_auth = yes
auth_mechanisms = plain login
!include auth-sql.conf.ext     ## Only enable authentication through SQL and leave all other authentication methods disabled

现在我们需要定义auth-sql.conf.ext中指定的变量。这里的变量包括:

  • %u:用户名
  • %n; user@domain 中的 user 部分,如果没有域则与 %u 相同
  • %d:user@domain中的域部分,如果没有域则为空
  • %h:主目录

创建包含所需变量的文件,如图所示;

$ sudo vim /etc/dovecot/conf.d/auth-sql.conf.ext
passdb {
  driver = sql
  args = /etc/dovecot/dovecot-sql.conf.ext
}
#userdb {
#  driver = sql
#  args = /etc/dovecot/dovecot-sql.conf.ext
#}

userdb {
  driver = static     ## Don't forget to change this
  args = uid=vmail gid=vmail home=/home/vmail/%d/%n/Maildir
}

现在我们将创建目录;

sudo mkdir /home/vmail/example.com

添加 Postfix 的数据库信用

$ sudo vim /etc/dovecot/dovecot-sql.conf.ext
driver = mysql
connect = "host=127.0.0.1 dbname=postfix_accounts user=postfix_admin password=StrongPassw0rd"
default_pass_scheme = SHA512-CRYPT
password_query = SELECT Email as User, password FROM accounts_table WHERE Email='%u';

接下来,通过编辑以下文件来配置邮箱位置和命名空间:

$ sudo vim /etc/dovecot/conf.d/10-mail.conf
mail_location = maildir:/home/vmail/%d/%n/Maildir

namespace inbox {
  inbox = yes
}

mail_privileged_group = mail

最后,打开 /etc/dovecot/conf.d/10-master.conf 并进行以下更改。

$ sudo vim /etc/dovecot/conf.d/10-master.conf 
service imap-login {
  inet_listener imap {
    port = 143
  }
  inet_listener imaps {
    port = 993
    ssl = yes
  }
}
service pop3-login {
  inet_listener pop3 {
    port = 110
  }
  inet_listener pop3s {
    port = 995
    ssl = yes
  }
}
service submission-login {
  inet_listener submission {
    #port = 587
  }
}
service lmtp {
  unix_listener /var/spool/postfix/private/dovecot-lmtp {
   mode = 0600
   user = postfix
   group = postfix
  }
}
service auth {
  unix_listener /var/spool/postfix/private/auth {
    mode = 0666
    user = postfix
    group = postfix
  }
  unix_listener auth-userdb {
   mode = 0600
   user = vmail
  }
  user = dovecot
}
service auth-worker {
  user = vmail
}
service dict {
  unix_listener dict {
  }
}

为了能够从 Postfix 接收电子邮件,请在文件底部添加以下行:

service stats {
    unix_listener stats-reader {
        user = vmail
        group = vmail
        mode = 0660
    }

    unix_listener stats-writer {
        user = vmail
        group = vmail
        mode = 0660
    }
}

为创建的目录设置所需的权限;

sudo chown -R vmail:vmail /home/vmail
chmod -R 775 /home/vmail

为用户设置其他所需的权限:

sudo chown -R vmail:dovecot /etc/dovecot 
sudo chmod -R o-rwx /etc/dovecot 

您可以对 Dovecot SSL 进行以下配置。

$ sudo vim /etc/dovecot/conf.d/10-ssl.conf
ssl = no

##If you want to use SSL here use ssl = required then add the files like:

ssl = required

ssl_cert = </etc/postfix/ssl/fullchain.pem
ssl_key = </etc/postfix/ssl/privkey.pem

如果您不需要任何使用 SSL 的意图,可以选择将其设置为 no。如果需要,请按照上图所示进行调整。

重新启动 Dovecot 服务:

sudo systemctl restart dovecot

验证服务是否正在运行:

$ systemctl status dovecot
● dovecot.service - Dovecot IMAP/POP3 email server
   Loaded: loaded (/usr/lib/systemd/system/dovecot.service; disabled; vendor preset: disabled)
   Active: active (running) since Sun 2022-10-02 08:52:31 UTC; 2s ago
     Docs: man:dovecot(1)
           https://doc.dovecot.org/
  Process: 7709 ExecStartPre=/usr/libexec/dovecot/prestartscript (code=exited, status=0/SUCCESS)
 Main PID: 7716 (dovecot)
    Tasks: 4 (limit: 48239)
   Memory: 4.6M
   CGroup: /system.slice/dovecot.service
           ├─7716 /usr/sbin/dovecot -F
           ├─7717 dovecot/anvil
           ├─7718 dovecot/log
           └─7719 dovecot/config

步骤 6 – 在 Rocky Linux 8 上安装和配置 Roundcube

现在我们需要设置一个基于网络的客户端来管理电子邮件。首先,从官方 Roundcube 页面获取最新的稳定 Roundcube 版本。

您还可以使用下面的脚本来提取最新版本。

VER="$(curl -s https://api.github.com/repos/roundcube/roundcubemail/releases/latest|grep tag_name|cut -d '"' -f 4|sed 's/v//')"
wget https://github.com/roundcube/roundcubemail/releases/download/$VER/roundcubemail-$VER-complete.tar.gz

下载后,解压存档。

sudo dnf install tar -y
tar xvzf roundcubemail-$VER-complete.tar.gz

重命名该文件并将其移动到 Apache webroot 目录;

mv roundcubemail-$VER roundcube
sudo mv roundcube /var/www/html/

允许 apache 访问这些文件:

sudo chown -R apache:apache /var/www/html/

在 Apache 上启用 HTTPS 模块

sudo dnf install mod_ssl -y

要应用更改,请重新启动 Apache 服务:

sudo systemctl restart httpd

允许服务通过防火墙:

sudo firewall-cmd --permanent --add-port=80/tcp
sudo firewall-cmd --reload

现在使用 URL https://domain_name/roundcube/installer 从网络访问 Roundcube

确保所有 PHP 检查均已通过,然后单击下一步。配置数据库凭据。

完成后,单击“创建配置”。您将在 /var/www/html/roundcube/config 创建配置

单击继续并继续初始化数据库。

现在设置配置所需的权限并进行相应的修改。

sudo chown apache:apache /var/www/html/roundcube/config/config.inc.php
sudo vim /var/www/html/roundcube/config/config.inc.php

提供 SMTP 主机、端口和登录方法,如图所示。

// IMAP
.....
#$config['imap_host'] = 'localhost:143'; ## If SSL is configured, use: 
$config['default_host'] = 'ssl://mail.example.com';

#$config['smtp_host'] = 'localhost';   ## If SSL is confgured, use: 
$config['smtp_host'] = 'tls://mail.example.com';

$config['support_url'] = '';

$config['default_port'] = 993;
$config['smtp_port'] = 587;
$config['smtp_user'] = '%u';
$config['smtp_pass'] = '%p';
$config['smtp_auth_type'] = 'LOGIN';
$config['debug_level'] = 1;
$config['smtp_debug'] = true;
$config['auto_create_user'] = true;
$config['plugins'] = array('virtuser_query'); 
$config['virtuser_query'] = "SELECT Email FROM postfix_accounts.accounts_table WHERE Email = '%u'"; ## Enables Roundcube to use authentication for virtual users for outgoing mail

在网络上,所有检查都应通过,如下所示。

现在按照页面底部的建议删除安装程序目录。

步骤 7 – 测试邮件服务器

现在我们需要允许所有必需的端口通过防火墙。这些端口包括:

  • HTTPS:443
  • IMAP:143
  • IMAP 安全:993
  • POP3:110
  • POP3 安全:995
  • 邮件发送:25
  • SMTP 安全:465
  • 管理系统分析:587

用于此任务的命令是:

sudo firewall-cmd --permanent --add-port={443,25,110,143,465,587,993,995}/tcp
sudo firewall-cmd --reload

现在为了测试一切是否正常,我们将从 Web 浏览器加载 Roundcube,网址为 http://domain_name/roundcube

要登录,请使用之前配置的任何帐户和用户名。例如:

登录后,您就可以从本地和远程服务器发送和接收电子邮件。

单击撰写创建示例电子邮件,然后按所示操作。

发送后,消息应显示在“已发送”下方,如图所示;

从收件箱,您可以看到邮件服务器上收到的邮件

判决

这标志着本指南关于如何使用 Postfix、Dovecot、MySQL 和 RoundCube 在 Rock Linux 8 上设置邮件服务器的结束。此时,您应该能够使用在 Rocky Linux 8 上配置良好的邮件交换记录来发送和接收电子邮件。

查看更多:

  • 在 Rocky Linux 8|AlmaLinux 8|RHEL 8 上安装 Zimbra 9 邮件服务器
  • 在 Debian 上安装和设置 iRedMail 邮件服务器
  • 在 CentOS 上使用 PostfixAdmin 配置邮件服务器
©2015-2025 Norria support@alaica.com