Dovecot 是类 Unix 操作系统上 IMAP 和 POP3 的开源服务。它专注于可用于大多数 Linux 操作系统的轻量级且安全的邮件服务器。
POP3(邮局协议 3)和 IMAP(互联网消息访问协议)都是用作消息访问代理的协议。这些协议用于从邮件服务器上的用户收件箱中获取电子邮件。简而言之,POP3 和 IMAP 负责从邮箱中获取邮件并在您的移动设备或 Web 界面上显示。
本教程将帮助您在 Debian 10 系统上安装和配置 Dovecot 服务。
先决条件
- 正在运行的 Debian 10 系统
- 预先配置的邮件服务器和用户邮箱
- 使用 root 或 sudo 特权帐户进行 shell 访问
步骤 1 – 在 Debian 上安装 Dovecot
基于 Debian 的系统有用于 IMAP 和 POP3 协议的单独的 Dovecot 软件包。要安装支持 POP3 和 IMAP 功能的 Dovecot 服务器,请运行以下命令:
sudo apt install dovecot-imapd dovecot-pop3d
您还可以安装各种 Dovecot 模块,例如 MySQL 和 PostgreSQL 数据库支持、邮件过滤、全文搜索、垃圾邮件过滤器培训和 ldap 目录。要安装附加模块,请运行:
sudo apt install dovecot-sieve dovecot-solr dovecot-antispam
步骤 2 – Dovecot 基本设置
安装完成后,根据您的要求配置 Dovecot 服务器。这是在您的系统上运行 Dovecot 的快速且有用的配置。
-
Enable Protocols: By default Dovecot has enabled POP3 and IMAP protocols in main configuration file. You can edit main configuration file and see:
sudo nano /etc/dovecot/dovecot.conf
!include_try /usr/share/dovecot/protocols.d/*.protocol
-
Listen Interface: By default Dovecot listen on all interfaces including IPV6. But if you need to restrict them to specific interface edit:
sudo nano /etc/dovecot/dovecot.conf
listen = *, ::
将“*”更改为接口IP,如“192.168.1.10”
-
Authentication: Then edit the authentication file for Dovecot and update following values.
sudo nano /etc/dovecot/conf.d/10-auth.conf
disable_plaintext_auth = no
auth_mechanisms = plain login
-
Setup Mailbox Directory: After that, edit mail configuration file to configure location of the Mailbox. Make sure to set this to correct location where your email server is configure to save users emails.
sudo nano /etc/dovecot/conf.d/10-mail.conf
mail_location = maildir:~/Maildir
-
Setup User: Next, edit below configuration file and set the username and group name of the mail server is running with.
sudo nano /etc/dovecot/conf.d/10-master.conf
unix_listener /var/spool/postfix/private/auth {
mode = 0666
user = postfix
group = postfix
}
-
Setup SSL: It is an good idea to enable SSL for the Dovecot. Edit file and set SSL to yes or required. By default it uses self singed certificate, if you have your own certificates update them as followings.
sudo nano /etc/dovecot/conf.d/10-ssl.conf
ssl = yes
ssl_cert =
第 3 步 - 管理 Dovecot 服务
我们可以使用 systemctl 命令行工具来管理 dovecot。使用以下命令启用 Dovecot 服务。
sudo systemctl enable dovecot.service
使用以下命令启动/停止或重新启动 Dovecot 服务:
sudo systemctl start dovecot.service
sudo systemctl stop dovecot.service
使用以下命令查看服务当前状态
sudo systemctl status dovecot.service
第 4 步 - 测试邮箱连接
为了测试此设置,我在 Debian 系统上创建了一个名为“rahul”的帐户。这mboxPostfix 服务器上的设置配置为〜/邮件目录目录。
接下来,您需要 mutt 命令行实用程序来使用 imaps 协议连接邮箱。
sudo apt install mutt
然后使用以下命令连接到邮箱:
mutt -f imaps://rahul@localhost
这将提示接受证书(按a总是接受)。之后它会提示输入密码。输入用户密码并按 Enter 键。您将看到您帐户的电子邮件。
第 5 步 - 调整 FirewallD 规则
对于运行防火墙的系统,需要允许以下端口以允许从网络访问。以下是 POP3 和 IMAP 协议使用的端口列表:
- IMAP-143
- IMAPS-993
- POP3-110
- POP3S-995
要添加防火墙规则,请执行以下命令:
sudo firewall-cmd --add-service={pop3,imap} --permanent
sudo firewall-cmd --add-service={pop3s,imaps} --permanent
然后重新加载更改。
sudo firewall-cmd --reload
结论
在本教程中,您学习了在 Debian 10 系统上安装和配置 Dovecot 服务器。您已将服务器配置为通过 POP3 或 IMAP 协议访问用户邮箱。