使用Docker部署mailcow,自建邮局服务(一)

先决条件

  • 一台VPS,有独立IP,最低配置1C2G,建议2C4G以上,支持发件服务(未屏蔽邮件端口, 请咨询你的服务商),支持PTR反向解析(咨询你的服务商)
  • 操作系统:CentOS、Debian、Ubuntu均可
  • 安装了Docker和docker-composer
  • 一个域名,注册时间越长越好,建议使用主流后缀,如:.com/.net/.org

部分CentOS 7系统可能内置了postfix服务,会和mailcow端口冲突,可以先尝试执行下面的命令卸载postfix

#CentOS卸载postfix
yum -y remove postfix

#Debian或者Ubuntu卸载postfix
apt-get remove postfix

设置Linux主机名

假设您的顶级域名为domain.com,那么您的主机名需要设置为mail.domain.commx.domain.com,前缀自己取,反正是需要二级域名。

设置主机名的命令为:

hostnamectl set-hostname mail.domain.com

然后修改/etc/hosts,添加一行hosts解析,就是将mail.domain.com指向到您当前服务器的公网IP,命令如下:

echo '173.0.xx.xxx    mail.domain.com' >> /etc/hosts

部署mailcow

先克隆mailcow代码和脚本:

#CentOS安装Git
yum -y install git

#Debian安装Git
apt-get install git

#克隆mailcow代码
git clone https://github.com/mailcow/mailcow-dockerized

进入代码目录cd mailcow-dockerized执行初始化脚本:./generate_config.sh根据提示设置域名和时区等信息。注意:

  1. 域名要和上面设置的主机名一致,比如mail.domain.com
  2. 如果后续需要修改,可以编辑mailcow.conf这个配置文件

mailcow默认使用了80/443作为WEB端口,如果您的服务器上已经存在WEB服务,可能会导致端口冲突,我们可以修改mailcow.conf这个配置文件,将

HTTP_PORT=80
HTTPS_PORT=443

修改为其它端口,比如修改为:

HTTP_PORT=880
HTTPS_PORT=8443

然后执行下面的命令拉取容器镜像和启动:

#拉取镜像
docker-compose pull

#启动容器
docker-compose up -d

初始化mailcow和添加域名

安装成功后,访问您的IP + 端口进入WEB管理界面,默认用户名:admin,密码为:moohoo

进入后台后点右上方“配置 – 邮箱设置 – 添加域名”

注意:添加域名的时候这里需要填写您的顶级域名domian.com,比如您主机名设置的是mail.domain.com,那么这里添加域名的时候填写domain.com

添加邮箱解析

域名添加完毕后,右侧有个DNS按钮,点击这个按钮会对您的域名DNS进行检测和指引。

不过那个检测有点不准,而且并非所有记录都要添加,下面是必须添加的记录。

主机名记录类型记录值备注
mail.domain.comA您的IP填写你VPS的公网IP
您的IPPTRmail.domain.com可能需要联系服务商添加
domain.comMXmail.domain.com
autodiscover.domain.comCNAMEmail.domain.com
autoconfig.domain.comCNAMEmail.domain.com
domain.comTXTv=spf1 a mx ip4:173.0.xx.xxx ~allIP改成你自己的
dkim._domainkey.domain.comTXT从mailcow后台获取DKIM记录从mailcow后台获取

邮件测试

DNS解析添加完毕后,等待几分钟生效,然后在mailcow后台添加邮箱账号,并登录webmail进行发件测试。

打开 https://www.mail-tester.com/ 这个网站,然后用你的mailcow邮箱发送邮件,发送完毕后查看得分。

满分为10分,如果评分很差,mail-tester会给出提示,建议根据提示进行修正即可。

总结

上述步骤我们仅仅是完成了安装和初始化,其实后续还有很多配置和维护工作要做。比如禁用IPV6、反向代理、配置SSL证书、数据备份与恢复等,有兴趣的可以参考mailcow官方文档完成,后续xiaoz再分享mailcow配置方面的内容。

自建邮局比较复杂且步骤繁多,很多细节问题若处理不好很容易进垃圾箱。非必要情况建议使用第三方企业邮箱即可,除非有特殊需求。自建邮局虽然不受发件量限制,但不建议短时间内发送大量垃圾邮件,否则你的IP或域名很容易被拉黑,最后得不偿失。

mailcow官网:https://mailcow.email/

sanradar
sanradar
文章: 97

22 评论

  1. Hi there, just became alert to your blog through Google,
    and found that it is really informative. I am gonna watch out for brussels.
    I will be grateful if you continue this in future. Numerous people will
    be benefited from your writing. Cheers! Escape roomy lista

  2. Having read this I thought it was very enlightening. I appreciate you taking the time and energy to put this information together. I once again find myself personally spending a significant amount of time both reading and commenting. But so what, it was still worthwhile.

  3. Oh my goodness! Awesome article dude! Thanks, However I am going through troubles with your RSS. I don’t understand why I can’t subscribe to it. Is there anyone else getting similar RSS problems? Anyone that knows the answer will you kindly respond? Thanx.

  4. Spot on with this write-up, I honestly believe this site needs a great deal more attention. I’ll probably be back again to read through more, thanks for the advice!

  5. You ought to take part in a contest for one of the greatest blogs on the web. I most certainly will highly recommend this website!

  6. Oh my goodness! Awesome article dude! Thank you, However I am encountering troubles with your RSS. I don’t know why I can’t join it. Is there anyone else having identical RSS issues? Anyone that knows the solution can you kindly respond? Thanks!

  7. I must thank you for the efforts you have put in writing this website. I am hoping to see the same high-grade blog posts from you in the future as well. In truth, your creative writing abilities has inspired me to get my very own website now 😉

  8. Oh my goodness! Impressive article dude! Many thanks, However I am experiencing troubles with your RSS. I don’t understand the reason why I can’t subscribe to it. Is there anybody else having identical RSS issues? Anyone who knows the answer will you kindly respond? Thanks!!

  9. Good post. I learn something new and challenging on blogs I stumbleupon every day. It’s always exciting to read content from other writers and use something from other web sites.

  10. Greetings! Very useful advice within this post! It is the little changes which will make the most significant changes. Thanks for sharing!

留下评论

您的电子邮箱地址不会被公开。 必填项已用 * 标注