调试 Debian 上的邮件服务(如 Postfix、Exim、Sendmail 或 Dovecot)通常需要从 服务状态、日志、配置、网络、DNS 等多个方面入手。下面以 Postfix(最常见) 为主,给你一套系统化的调试思路。
先确认你用的是哪种 MTA:
systemctl list-units --type=service | grep -E 'postfix|exim|sendmail|dovecot'
常见组合:
下面以 Postfix 为例。
systemctl status postfix
systemctl status dovecot
如果没启动:
systemctl start postfix
systemctl enable postfix
Debian 默认日志位置:
journalctl -u postfix -f
# 或
tail -f /var/log/mail.log
常见关键词:
status=sent ✅ 发送成功status=deferred ⏳ 临时失败status=bounced ❌ 永久失败connection timed outrelay access deniedSender address rejectedecho "test" | mail -s "test mail" user@localhost
或:
sendmail user@localhost
Subject: test
test
.
然后查看:
tail -f /var/log/mail.log
postconf -n
常见问题点:
myhostname =
mydomain =
myorigin =
inet_interfaces =
mydestination =
relayhost =
测试配置语法:
postfix check
重载配置:
systemctl reload postfix
邮件常用端口:
查看监听:
ss -tulnp | grep -E '25|465|587|110|143'
防火墙(如启用):
ufw status
如果是公网邮件服务器,必须检查:
dig MX yourdomain.com
dig -x 你的服务器IP
TXT 记录opendkimTXT 记录telnet localhost 25
示例:
HELO test
MAIL FROM: test@localhost
RCPT TO: user@localhost
DATA
Subject: test
hello
.
QUIT
| 问题 | 原因 |
|---|---|
| 邮件发不出去 | relayhost 未配置 |
| 外部收不到 | 防火墙 / DNS / 被当成垃圾邮件 |
| 认证失败 | SASL / Dovecot 配置错误 |
| 本地能发不能收 | dovecot 未运行 |
| 队列堆积 | postqueue -p |
查看队列:
postqueue -p
postsuper -d ALL deferred
你可以直接贴出:
postconf -n/var/log/mail.log 报错片段我可以帮你精确定位问题。