测试 Debian 邮件服务可以从 服务状态、端口监听、本地收发、远程连通性、日志排错 等方面逐步进行。下面按常见场景给你一套完整流程(适用于 Postfix / Exim / Dovecot 等)。
ps aux | grep -E 'postfix|exim|sendmail'
常见组合:
systemctl status postfix
systemctl status dovecot
如未启动:
systemctl start postfix
systemctl start dovecot
邮件服务常用端口:
| 服务 | 端口 |
|---|---|
| SMTP | 25 |
| SMTPS | 465 |
| Submission | 587 |
| IMAP | 143 |
| IMAPS | 993 |
| POP3 | 110 |
| POP3S | 995 |
查看监听状态:
ss -lntp
# 或
netstat -lntp
示例(正常):
*:25 LISTEN master (postfix)
*:993 LISTEN dovecot
mail / mailx安装:
apt install mailutils
发送测试邮件:
echo "Test email body" | mail -s "Test Subject" user@localhost
查看本地邮箱:
mail
sendmail 接口sendmail user@localhost <<EOF
Subject: Test Mail
From: root@localhost
This is a test.
EOF
postqueue -p
清空队列(慎用):
postqueue -f
tail -f /var/log/mail.log
发送邮件时观察日志:
tail -f /var/log/mail.log
常见错误:
Relay access deniedConnection refusedUser unknownTLS errortelnettelnet localhost 25
输入:
HELO test.com
MAIL FROM:<test@test.com>
RCPT TO:<user@localhost>
DATA
Hello
.
QUIT
✅ 成功会看到 250 OK
swaks(强烈推荐)安装:
apt install swaks
测试 SMTP:
swaks --to user@localhost --from test@test.com
telnet localhost 143
或使用 OpenSSL(IMAPS):
openssl s_client -connect localhost:993
doveadm 检查邮箱doveadm user user@localhost
dig MX yourdomain.com
应看到:
yourdomain.com. MX 10 mail.yourdomain.com.
echo "test" | mail -s "test" you@qq.com
⚠️ 注意:
✅ 防火墙是否放行端口
✅ /etc/postfix/main.cf 是否配置正确
✅ 是否允许中继(mynetworks)
✅ 域名是否能解析
✅ 是否被当成垃圾邮件
systemctl status postfix dovecot
ss -lntp
tail -f /var/log/mail.log
postqueue -p
swaks --to user@localhost
如果你愿意,可以告诉我:
我可以按你的实际配置给你一份精确测试方案。