王锐
王锐
发布于 2026-01-03 / 18 阅读
0
1

邮件收发平台搭建(mailcow)

参考:mailcow: dockerized documentation

一、配置docker文件

  1. 下载mailcow-dockerized源码

git clone https://github.com/mailcow/mailcow-dockerized
cd mailcow-dockerized
  1. 生成配置文件

./generate_config.sh
  1. 调整配置文件

vim mailcow.conf

作者所使用nginx不参与https加解密,仅负责http的服务提供,外部nginx提供证书申请功能,因此会修改相应的位置如下:

# You should use HTTPS, but in case of SSL offloaded reverse proxies:
# Might be important: This will also change the binding within the container.
# If you use a proxy within Docker, point it to the ports you set below.
# Do _not_ use IP:PORT in HTTP(S)_BIND or HTTP(S)_PORT
# IMPORTANT: Do not use port 8081, 9081, 9082 or 65510!
# Example: HTTP_BIND=1.2.3.4
# For IPv4 leave it as it is: HTTP_BIND= & HTTPS_PORT=
# For IPv6 see https://docs.mailcow.email/post_installation/firststeps-ip_bindings/
[------] HTTP_PORT=80
[++++++] HTTP_PORT=10080
HTTP_BIND=

[------] HTTPS_PORT=443
[++++++] HTTPS_PORT=10443
HTTPS_BIND=

# Redirect HTTP connections to HTTPS - y/n
[------] HTTP_REDIRECT=y
[++++++] HTTP_REDIRECT=n # 重要:关闭内部强制跳转,交给外部处理

# Skip running ACME (acme-mailcow, Let's Encrypt certs) - y/n
[------] SKIP_LETS_ENCRYPT=n
[++++++] SKIP_LETS_ENCRYPT=y

# 为了二避免端口冲突,做了如下修改,转发到公网服务器时,会通过frp映射到原本的端口上
[------] SMTP_PORT=25
[------] SMTPS_PORT=465
[------] SUBMISSION_PORT=587
[------] IMAP_PORT=143
[------] IMAPS_PORT=993
[------] POP_PORT=110
[------] POPS_PORT=995
[------] SIEVE_PORT=4190
[++++++] SMTP_PORT=10025
[++++++] SMTPS_PORT=10465
[++++++] SUBMISSION_PORT=10587
[++++++] IMAP_PORT=10143
[++++++] IMAPS_PORT=10993
[++++++] POP_PORT=10110
[++++++] POPS_PORT=10995
[++++++] SIEVE_PORT=14190
  1. 配置成功后运行容器

sudo docker compose up -d

注意:网络地址建议使用172.22.1保持不变,作者使用172.32.1网段,结果导致DNS一直不通,最终还原为22网段才恢复正常

二、端口转发设置

本人家用电脑部署服务,云服务器仅作流量转发功能,因此需要进行端口转发

  1. frp配置如下:

[SMTP_PORT]
type = tcp
local_ip = 10.44.0.11
local_port = 10025
remote_port = 25


[SMTPS_PORT]
type = tcp
local_ip = 10.44.0.11
local_port = 10465
remote_port = 465


[SUBMISSION_PORT]
type = tcp
local_ip = 10.44.0.11
local_port = 10587
remote_port = 587

[IMAP_PORT]
type = tcp
local_ip = 10.44.0.11
local_port = 10143
remote_port = 143


[IMAPS_PORT]
type = tcp
local_ip = 10.44.0.11
local_port = 10993
remote_port = 993

[POP_PORT]
type = tcp
local_ip = 10.44.0.11
local_port = 10110
remote_port = 110

[POPS_PORT]
type = tcp
local_ip = 10.44.0.11
local_port = 10995
remote_port = 995

[SIEVE_PORT]
type = tcp
local_ip = 10.44.0.11
local_port = 14190
remote_port = 4190
  1. 外部nginx配置如下:

server{
    server_name mail.hopo.dev;

    location / {
        proxy_pass http://10.44.0.11:10080;
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        client_max_body_size 0; # 允许大附件上传
    }
}

配置完成后,还需要激活,可参考: Ubuntu下使用Certbot配置Nginx免费证书

二、修改DNS

  1. The minimal DNS configuration

# Name              Type       Value
mail                IN A       1.2.3.4
autodiscover        IN CNAME   mail.example.org. (your ${MAILCOW_HOSTNAME})
autoconfig          IN CNAME   mail.example.org. (your ${MAILCOW_HOSTNAME})
@                   IN MX 10   mail.example.org. (your ${MAILCOW_HOSTNAME})
  1. DKIM, SPF and DMARC

# Name              Type       Value
@                   IN TXT     "v=spf1 mx a -all"

  1. 配置DKIM

# Name              Type       Value
dkim._domainkey     IN TXT     "v=DKIM1; k=rsa; t=s; s=email; p=..."
  1. 配置DMARC

# Name              Type       Value
_dmarc              IN TXT     "v=DMARC1; p=reject; rua=mailto:mailauth-reports@example.org"

三、配置邮箱

(1) 以admin登录后,需要配置邮箱

1、 电子邮件 -> 配置 -> 新增域名

2、 域名选填,例如使用 hopo.dev,其他选项按需设置,注意:不要选择中继这个域名,否则会导致收不到邮件,完成设置后点击确定

3、此时的dkim._domainkey可以在此页面上找到,将其添加到步骤3的配置中即可

(2) 添加用户

1、电子邮件 -> 配置 -> 信箱

2、添加新增信箱即可新增用户,按需新增即可

四、使用DEMO

网址: mail.hopo.dev

账号: demo@hopo.dev

密码: :&,34,NAtTee

进入mail.hopo.dev网页后,以上述账号密码登录即可体验使用mailcow收发邮件


评论