Docker 部署 iRedMail 搭建私人邮件服务器

2478人浏览 / 0人评论

参考

https://cloud.tencent.com/developer/article/2088199

https://blog.csdn.net/chscomfaner/article/details/125679522

https://iweec.com/221.html

官网:https://docs.iredmail.org/install.iredmail.on.rhel-zh_CN.html

官网下载:https://www.iredmail.org/download-zh_CN.html

官网 DNS 解析说明文档:https://docs.iredmail.org/setup.dns.html#how-to-setup-the-mx-record

官网使用 IMAP/SMTP 通过客户端收发邮件说明文档:https://docs.iredmail.org/configure.thunderbird.html

桌面邮件客户端:https://www.thunderbird.net/zh-CN/

安装

命令:

# 首先服务器和腾讯云的防火墙都要开放端口:80、443、110、995、143、993、25、465、587
# 如果使用内网穿透,那么要将客户端的这些端口映射到服务器
# 如果是服务器本地部署+frp内网穿透,可将常用的80、443端口改为10001、44301等,即:-p 10001:80 -p 44301:443,然后frpc使用https2https转发

# 下载iredmail镜像
docker pull iredmail/mariadb:stable

# 创建文件夹
mkdir /home/iredmail
cd /home/iredmail
mkdir -p data/{backup-mysql,clamav,custom,imapsieve_copy,mailboxes,mlmmj,mlmmj-archive,mysql,sa_rules,ssl,postfix_queue}

# 创建所需要的环境变量文件
echo HOSTNAME=mail.jbritian.com >> iredmail-docker.conf
echo FIRST_MAIL_DOMAIN=jbritian.com >> iredmail-docker.conf
echo FIRST_MAIL_DOMAIN_ADMIN_PASSWORD=123456 >> iredmail-docker.conf
echo MLMMJADMIN_API_TOKEN=$(openssl rand -base64 32) >> iredmail-docker.conf
echo ROUNDCUBE_DES_KEY=$(openssl rand -base64 24) >> iredmail-docker.conf
echo MYSQL_ROOT_PASSWORD=123456 >> iredmail-docker.conf

# 第一次启动
docker run \
    -d --privileged=true \
    --name iredmail \
    --env-file iredmail-docker.conf \
    --hostname mail.jbritian.com \
    -p 10001:80 \
    -p 44301:443 \
    -p 110:110 \
    -p 995:995 \
    -p 143:143 \
    -p 993:993 \
    -p 25:25 \
    -p 465:465 \
    -p 587:587 \
    -v /home/iredmail/data/backup-mysql:/var/vmail/backup/mysql \
    -v /home/iredmail/data/mailboxes:/var/vmail/vmail1 \
    -v /home/iredmail/data/mlmmj:/var/vmail/mlmmj \
    -v /home/iredmail/data/mlmmj-archive:/var/vmail/mlmmj-archive \
    -v /home/iredmail/data/imapsieve_copy:/var/vmail/imapsieve_copy \
    -v /home/iredmail/data/custom:/opt/iredmail/custom \
    -v /home/iredmail/data/ssl:/opt/iredmail/ssl \
    -v /home/iredmail/data/mysql:/var/lib/mysql \
    -v /home/iredmail/data/clamav:/var/lib/clamav \
    -v /home/iredmail/data/sa_rules:/var/lib/spamassassin \
    -v /home/iredmail/data/postfix_queue:/var/spool/postfix \
    iredmail/mariadb:stable

# 替换证书
cd /home/iredmail/data/ssl  # 将证书文件上传到该目录下,并替换cert.pem、combined.pem、key.pem三个文件:
cp mail.jbritian.com_bundle.crt cert.pem
cp mail.jbritian.com_bundle.crt combined.pem
cp mail.jbritian.com.key key.pem

# 删除容器
docker rm -f iredmail

# 重新启动
cd /home/iredmail
docker run \
    -d --privileged=true \
    --name iredmail \
    --env-file iredmail-docker.conf \
    --hostname mail.jbritian.com \
    -p 10001:80 \
    -p 44301:443 \
    -p 110:110 \
    -p 995:995 \
    -p 143:143 \
    -p 993:993 \
    -p 25:25 \
    -p 465:465 \
    -p 587:587 \
    -v /home/iredmail/data/backup-mysql:/var/vmail/backup/mysql \
    -v /home/iredmail/data/mailboxes:/var/vmail/vmail1 \
    -v /home/iredmail/data/mlmmj:/var/vmail/mlmmj \
    -v /home/iredmail/data/mlmmj-archive:/var/vmail/mlmmj-archive \
    -v /home/iredmail/data/imapsieve_copy:/var/vmail/imapsieve_copy \
    -v /home/iredmail/data/custom:/opt/iredmail/custom \
    -v /home/iredmail/data/ssl:/opt/iredmail/ssl \
    -v /home/iredmail/data/mysql:/var/lib/mysql \
    -v /home/iredmail/data/clamav:/var/lib/clamav \
    -v /home/iredmail/data/sa_rules:/var/lib/spamassassin \
    -v /home/iredmail/data/postfix_queue:/var/spool/postfix \
    iredmail/mariadb:stable
# 等待几分钟即可

# 登录系统,
https://mail.jbritian.com
# 用户名为:postmaster@jbritian.com
# 密码为:123456
# 登录后需要修改一下管理员密码

# 登录管理后台
https://mail.jbritian.com/iredadmin
# 用户名为:postmaster@jbritian.com
# 密码为:已修改

# 安装到这里基本完成,下一步是添加解析,让邮件服务器能够收发邮件,且不被QQ邮箱、网易邮箱等认定为垃圾邮件

腾讯云添加解析

主机记录 记录类型 记录值 MX优先级
mail A 部署 iredmail 的服务器的外网 ip  
@ MX mail.jbritian.com. 10
@ TXT v=spf1 mx -all  
dkim._domainkey TXT v=DKIM1;p=xxxxxxxxx  
_dmarc TXT v=DMARC1; p=none; pct=100; rua=mailto:postmaster@jbritian.com  

说明:

1、dkim._domainkey

它的记录值需要去容器中查看:

docker exec -it iredmail /bin/bash

# 执行:amavisd showkeys 或者 amavisd-new showkeys
# 结果跟下面类似:
dkim._domainkey.mydomain.com.   3600 TXT (
  "v=DKIM1; p="
  "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDYArsr2BKbdhv9efugByf7LhaK"
  "txFUt0ec5+1dWmcDv0WH0qZLFK711sibNN5LutvnaiuH+w3Kr8Ylbw8gq2j0UBok"
  "FcMycUvOBd7nsYn/TUrOua3Nns+qKSJBy88IWSh2zHaGbjRYujyWSTjlPELJ0H+5"
  "EV711qseo/omquskkwIDAQAB")

# 将所有引号去掉,并合并到一行即可

2、_dmarc

它的记录值中 postmaster@jbritian.com 应与 iredmail-docker.confPOSTMASTER_EMAIL 的值一样(默认为:postmaster@jbritian.com)。

3、如果你是需要用其他客户端软件来收取或是发送邮件,端口列表在这里:

协议 地址 端口 加密端口
IAMP mail.jbritian.com 143 993
POP3 mail.jbritian.com 110 995
SMTP mail.jbritian.com 25 587

它域互通

QQ:https://open.mail.qq.com/openmail/openmailhome#/

Gmail:https://postmaster.google.com/managedomains

软件及对应的端口

https://docs.iredmail.org/network.ports.html

全部评论