使用 IMAP 和 TLS 设置 Dovecot

来自 Alpine Linux

概述

Dovecot 应该配置为允许用户通过 TLS 获取邮件。目标是能够使用您喜欢的电子邮件客户端或移动设备(例如手机)获取邮件。

请查看 Hosting_services_on_Alpine#Mail 以获取各种替代方案和说明。

初始设置

本文档参考了 Setting_up_postfix_with_virtual_domains。如果您先阅读/遵循这些说明,然后再继续阅读这些说明,您将受益匪浅。

Dovecot

安装

apk add dovecot

准备

即将到来的配置将需要一些证书。

证书

在 Dovecot 的安装过程中,生成了一些默认证书,我们将替换它们。我们希望保持整洁,因此我们为它的证书/密钥创建一个 dovecot 文件夹

mkdir /etc/ssl/dovecot

现在我们开始创建证书

cd /etc/ssl/dovecot openssl genrsa 1024 > server.pem # 选择 512 或 1024 作为密钥长度 openssl req -new -key server.pem -out request.pem # 您将被提示输入添加到文件中的各种信息 openssl genrsa 2048 > server.key openssl req -new -x509 -nodes -sha1 -days 3650 -key server.key > server.pem

配置

目前我只是转储我拥有的任何东西。

我将尽快清理这些笔记。

/etc/dovecot/dovecot.conf

## These settings varies from the default configuration ##
base_dir = /var/run/dovecot/
protocols = imap imaps
listen = *
disable_plaintext_auth = no
ssl_disable = no
ssl_cert_file = /etc/ssl/dovecot/server.pem
ssl_key_file = /etc/ssl/dovecot/server.key
ssl_parameters_regenerate = 168
verbose_ssl = yes
login_chroot = yes
login_greeting = Dovecot ready.
mail_location = maildir:/var/spool/mail/vhosts/%d/%n
mail_privileged_group = mail
mail_debug = no
verbose_proctitle = no
valid_chroot_dirs = /var/spool/mail
protocols lda {     # This line is not changed - it's here to help you know where to make edits
  postmaster_address = postmaster@example.net
}     # This line is not changed - it's here to help you know where to make edits
auth_verbose = yes
auth_debug = yes
auth_worker_max_count = 30
auth default {     # This line is not changed - it's here to help you know where to make edits
  mechanism = plain login digest-md5
  passdb passwd-file {
    args = /etc/dovecot/dovecot-passwd
  }
  userdb passwd-file {
    args = /etc/dovecot/dovecot-users
  }
  socket listen {
    path = /var/spool/postfix/private/auth
    user = postfix
    group = postfix
    mode = 0660
  }
}     # This line is not changed - it's here to help you know where to make edits

/etc/dovecot/dovecot-users

下面 '1000' 的 uid/gid 编号应与您的 'vmail' 帐户(拥有 '/var/spool/mail/vhosts' 的帐户)匹配

user1@example.net::1000:1000::/var/spool/vhosts/example.net/:/bin/false::
user2@example.net::1000:1000::/var/spool/vhosts/example.net/:/bin/false::

/etc/dovecot/dovecot-passwd

要生成密码,您可以使用 dovecotpw 命令。输出可用于为您的 'dovecot-passwd' 创建密码

dovecotpw -s MD5-CRYPT

doveadm pw -s MD5-CRYPT

/etc/dovecot/passwd 文件应如下所示

user1@example.net:$1$tz5sbjAD$Wq9.NkSyNo/oElzFgI68.0
user2@example.net:$1$tz5sbjAD$Wq9.NkSyNo/oElzFgI68.0

启动 dovecot

是时候启动了。希望它能工作!

rc-service dovecot start

调试

如果出现问题,您应该查看您的 syslog。我个人在调试时习惯使用 tail 命令查看日志文件

tail -f /var/log/dovecot

添加/移除用户

要添加或删除用户,您需要编辑以下文件(上面已描述)

不需要其他任何操作。