温馨提示×

如何测试Debian邮件服务

小樊
42
2026-07-07 13:15:22
栏目: 智能运维

测试 Debian 邮件服务可以从 服务状态、端口监听、本地收发、远程连通性、日志排错 等方面逐步进行。下面按常见场景给你一套完整流程(适用于 Postfix / Exim / Dovecot 等)。


一、确认邮件服务是否已安装并运行

1. 查看 MTA 类型

ps aux | grep -E 'postfix|exim|sendmail'

常见组合:

  • Postfix + Dovecot(最常见)
  • Exim(Debian 默认有时是 Exim)

2. 检查服务状态

Postfix

systemctl status postfix

Dovecot(IMAP/POP3)

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

三、本地发送测试邮件

方法 1:使用 mail / mailx

安装:

apt install mailutils

发送测试邮件:

echo "Test email body" | mail -s "Test Subject" user@localhost

查看本地邮箱:

mail

方法 2:使用 sendmail 接口

sendmail user@localhost <<EOF
Subject: Test Mail
From: root@localhost

This is a test.
EOF

四、查看邮件队列和日志(非常重要)

1. 查看邮件队列

postqueue -p

清空队列(慎用):

postqueue -f

2. 查看日志

Debian 默认日志

tail -f /var/log/mail.log

发送邮件时观察日志:

tail -f /var/log/mail.log

常见错误:

  • Relay access denied
  • Connection refused
  • User unknown
  • TLS error

五、测试 SMTP(命令行)

使用 telnet

telnet 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

六、测试 IMAP / POP3

测试 IMAP

telnet localhost 143

或使用 OpenSSL(IMAPS):

openssl s_client -connect localhost:993

使用 doveadm 检查邮箱

doveadm user user@localhost

七、测试远程邮件收发(真实环境)

1. 检查 DNS

dig MX yourdomain.com

应看到:

yourdomain.com. MX 10 mail.yourdomain.com.

2. 测试发往外部邮箱

echo "test" | mail -s "test" you@qq.com

⚠️ 注意:

  • 云服务器 25 端口常被封
  • 建议启用 587 + STARTTLS
  • 配置 SPF / DKIM / DMARC

八、常见问题排查清单

✅ 防火墙是否放行端口
/etc/postfix/main.cf 是否配置正确
✅ 是否允许中继(mynetworks)
✅ 域名是否能解析
✅ 是否被当成垃圾邮件


九、快速自检命令汇总

systemctl status postfix dovecot
ss -lntp
tail -f /var/log/mail.log
postqueue -p
swaks --to user@localhost

如果你愿意,可以告诉我:

  • 你用的是 Postfix 还是 Exim
  • 本地测试 还是 公网邮件服务器
  • 是否启用了 SSL / TLS

我可以按你的实际配置给你一份精确测试方案

0