使用docker安装maddy程序自建企业邮局 搭建域名邮箱

最近很多人都在搭建maddy邮局程序用来发信,我也来研究一下。
maddy程序是自建企业邮局或搭建域名邮箱的又一个出路。
maddy是golang编写的邮局程序,占用内存极低。
我测试了一下,装完占用22M内存。
提前总结:仅推荐个人折腾,除了占用内存少,其他都是缺点。
中文文档少,功能少,还是命令行控制,没有API。

1.安装nginx并且配置

apt -y install curl nginx

echo -ne "
server {
    listen 80;
    server_name example.com mail.example.com www.example.com;
    root /usr/share/nginx/html;
}
" > /etc/nginx/conf.d/example.com.conf

2.安装acme.sh


wget -O -  https://get.acme.sh | sh -s [email protected]

3.颁发证书

尽量别用DNS验证,DNS等了半个小时都没生效,太坑了。
sh /root/.acme.sh/acme.sh  --issue  -w  /usr/share/nginx/html -d example.com -d www.example.com -d mail.example.com

4.安装证书

Your cert is in: /root/.acme.sh/example.com_ecc/example.com.cer
Your cert key is in: /root/.acme.sh/example.com_ecc/example.com.key
The intermediate CA cert is in: /root/.acme.sh/example.com_ecc/ca.cer
And the full chain certs is there: /root/.acme.sh/example.com_ecc/fullchain.cer
这里先准备maddy的存放目录
 mkdir  -p /data/maddydata/tls
 acme.sh --install-cert -d example.com -d mail.example.com \
--key-file    /data/maddydata/tls/privkey.pem  \
--fullchain-file  /data/maddydata/tls/fullchain.pem  
--reloadcmd     "docker restart maddy" 

5.安装docker


curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh 

6.配置docker文件并启动maddy

a.准备maddy的配置文件
mkdir  -p /data/maddydata/tls
curl -L https://raw.githubusercontent.com/foxcpp/maddy/master/maddy.conf.docker -o   /data/maddydata/maddy.conf

b.启动maddy

docker run \
  --name maddy \
  -e MADDY_HOSTNAME=example.com \
  -e MADDY_DOMAIN=example.com \
  -v /data/maddydata:/data \
  -p 25:25 \
  -p 143:143 \
  -p 465:465 \
  -p 587:587 \
  -p 993:993 \
  foxcpp/maddy:latest 

7.创建用户,然后根据提示输入密码


docker exec -it maddy maddy creds create [email protected]
 #同时创建本地存储账户, 用户名请与上方保持一致
docker exec -it maddy maddy imap-acct create [email protected]

更多命令
docker exec -it maddy maddyctl creds list 列出当前所有用户
docker exec -it maddy maddyctl creds create [email protected] 创建用户
docker exec -it maddy maddyctl creds remove [email protected] 删除用户
docker exec -it maddy myaddyctl creds password [email protected] 修改密码

8.配置DNS记录

设置mx记录 ,mx类型
设置spf记录 ,txt类型 v=spf1 mx ip4:8.8.8.8 ~all
设置DKIM记录,txt类型 default._domainkey
cat /data/maddydata/dkim_keys/example.com_default.dns
rDNS 如果没有rDNS,某些邮局会拒绝收信

9.客户端设置

服务器名为你设置的hostname,我设置的与邮箱域名一样
默认普通密码
发信:
STARTTLS 587
SSL/TLS 465 推荐
IMAP收信:
STARTTLS 143
SSL/TLS 993 推荐

10. 邮件中继发信

这个简单的问题,我测试了一天才解决,全网独家。
很简单,替换以下整个代码块
target.remote outbound_delivery {
    省略内容
}


    target.smtp outbound_delivery {

    attempt_starttls yes
    require_tls   yes
    auth off
  #auth plain [email protected] password
    targets tls://10.10.10.10:465

  }

参考文章:
https://lists.sr.ht/~foxcpp/maddy/%3CC8M83UATR2O5.1CBF3H47DQ4VT%40tiggercloud%3E
https://maddy.email/

此处评论已关闭