史上最强 搭建邮件服务器
docker-mailserver/docker-mailserver
参考: https://www.itmanbu.com/docker-mail-server.html
https://blog.csdn.net/hxpjava1/article/details/80669355
注意!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
以下示例是在arm64平台上搭建的, 机器是x96max+刷了armbian(基于debian)系统
如果是直接在云服务器上是用不到端口映射的
最后的结论可能就是因为端口映射导致不能收其他域名邮件
创建目录
mkdir ~/docker/mail && cd ~/docker/mail
vim docker-compose.yml # docker-compose
version: '2'
services:
mailserver:
image: docker.io/mailserver/docker-mailserver:9.1.0
hostname: mail # 名称
domainname: sddphp.cn # 域名
container_name: mailserver
ports:
- "25:25"
- "143:143"
- "587:587"
- "993:993"
volumes:
- maildata:/var/mail
- mailstate:/var/mail-state
- maillogs:/var/log/mail
- ./config/:/tmp/docker-mailserver/
- /etc/ssl:/tmp/ssl:ro
environment:
- PERMIT_DOCKER=network # 内网端口转发, 一定要加这个
- ENABLE_SPAMASSASSIN=0
- ENABLE_CLAMAV=0
- ENABLE_FAIL2BAN=1
- ONE_DIR=1
- DMS_DEBUG=0
- SSL_TYPE=manual
- SSL_CERT_PATH=/tmp/ssl/fullchain.cer
- SSL_KEY_PATH=/tmp/ssl/sddphp.cn.key
- TZ=Asia/Shanghai
cap_add:
- NET_ADMIN
- SYS_PTRACE
restart: always
volumes:
maildata:
mailstate:
maillogs:
wget https://raw.githubusercontent.com/docker-mailserver/docker-mailserver/master/mailserver.env # 环境配置
wget https://raw.githubusercontent.com/docker-mailserver/docker-mailserver/v10.0.0/setup.sh # 脚本, 用于设置用户和DKIM
chmod a+x ./setup.sh
./setup.sh help
docker-compose up -d mailserver
./setup.sh email add [email protected] [<password>]
./setup.sh config dkim keysize 1024 domain sddphp.cn
docker-compose pull
docker-compose down
docker-compose up -d mailserver
vim update.sh # 更新脚本
#! /bin/bash
docker-compose down
docker-compose up -d
端口映射
[993mail]
# mail
type = tcp
local_ip = 127.0.0.1
local_port = 993
remote_port = 993
[587mail]
# mail
type = tcp
local_ip = 127.0.0.1
local_port = 587
remote_port = 587
复制证书
复制到/etc/ssl
目录
/etc/ssl/
├── fullchain.cer
└── sddphp.cn.key
配置DKIM
cat config/opendkim/keys/sddphp.cn/mail.txt
mail._domainkey IN TXT ( "v=DKIM1; h=sha256; k=rsa; "
"p=XXXXXXXXXXXX" ) ; ----- DKIM key mail for sddphp.cn
阿里云解析
mail._domainkey TXT 默认 v=DKIM1;h=sha256;k=rsa;p=XXXXXX
@ MX 默认 mail.sddphp.cn | 10
_dmarc TXT 默认 v=DMARC1; p=none
@ TXT 默认 v=spf1 mx ~all
测试
docker exec mailserver openssl s_client -connect 0.0.0.0:587 -starttls smtp -CApath /etc/ssl/
docker exec mailserver openssl s_client -connect 0.0.0.0:993 -starttls smtp -CApath /etc/ssl/
通过:
Verify return code: 0 (ok)
结果
配置后可以发邮件正常, 可以收内网邮件, 不能收其他域名发来的邮件, 正在解决中…
20210624 已解决
- PERMIT_DOCKER=network # 内网端口转发, 一定要加这个
https://github.com/docker-mailserver/docker-mailserver/issues/1405
查看日志
docker logs -f mailserver
tail -f /var/lib/docker/volumes/mail_maillogs/_data/mail.log