邮件运维排障
投递失败、DNS 记录与日志对照。
30 分钟
邮件系统搭建与日常运维
把 dnm-smtp、dnm-imap、dnm-auth-mail 串联起来:Postfix 发信 + Dovecot 收信 + DNS 认证 + 监控备份。本课给出单机最小可用栈与 relay 混合架构(推荐生产),结合 linux-essentials 服务管理、networking-essentials 防火墙与端口、dns-essentials 记录配置、git-essentials 配置版本化。
学习目标
- 部署 Postfix + Dovecot 最小邮件栈(或 relay 架构)
- 配置 Let's Encrypt 证书与防火墙规则
- 建立邮件系统 监控、队列、备份 日常 SOP
架构选型
| 架构 | 组件 | 适用 |
|---|---|---|
| Relay 混合(推荐) | Postfix relay → SendGrid/SES;Dovecot 仅内网 IMAP | SaaS 发信 + 自建收信 |
| 全自建 MTA | Postfix 直连 25 端口 | 需 IP 信誉、反垃圾运维 |
| 全 SaaS | 无 Postfix,API 发 + 云邮箱收 | 小团队、零运维 |
Relay 混合架构
App ──587──► Postfix ──relay──► SendGrid ──► 互联网
运维 ──993──► Dovecot ──► Maildir(内网/archive)
DNS: MX + SPF + DKIM + DMARC
安装与基础配置
# Debian/Ubuntu
sudo apt update
sudo apt install postfix dovecot-imapd dovecot-lmtpd certbot
# Postfix 安装时选 "Internet Site",mydomain = example.com
/etc/postfix/main.cf(relay 模式):
myhostname = mail.example.com
mydomain = example.com
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
relayhost = [smtp.sendgrid.net]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_tls_security_level = encrypt
smtpd_tls_cert_file = /etc/letsencrypt/live/mail.example.com/fullchain.pem
smtpd_tls_key_file = /etc/letsencrypt/live/mail.example.com/privkey.pem
sudo postmap /etc/postfix/sasl_passwd
sudo systemctl enable --now postfix dovecot