温馨提示×

如何测试Ubuntu邮件服务器

小樊
35
2026-07-05 13:10:58
栏目: 云计算

测试 Ubuntu 邮件服务器可以从 基本连通性、SMTP 发信、IMAP/POP3 收信、认证与加密、垃圾邮件与反病毒 等多个方面进行。下面按由浅入深的方式给你一套完整测试流程(适用于 Postfix / Dovecot 常见组合)。


一、测试前准备

1. 确认服务状态

systemctl status postfix
systemctl status dovecot

确保都在 active (running)


2. 确认端口监听

ss -lntp

常见端口:

  • SMTP:25、465(SMTPS)、587(Submission)
  • IMAP:143、993(IMAPS)
  • POP3:110、995(POP3S)

示例:

ss -lntp | grep :25

二、本地基础测试(不依赖外网)

1. 测试 SMTP(发信)

使用 telnet(最基础)

telnet localhost 25

成功后输入:

EHLO test.com
MAIL FROM:<user1@yourdomain.com>
RCPT TO:<user2@yourdomain.com>
DATA
Hello, this is a test.
.
QUIT

✅ 成功标志:返回 250 OK


2. 测试 IMAP(收信)

telnet localhost 143
a login user@yourdomain.com 密码
a list "" "*"
a logout

✅ 成功说明 IMAP 正常


三、使用 mail / s-nail 工具测试

安装

sudo apt install mailutils

发送测试邮件

echo "Test body" | mail -s "Test subject" user@yourdomain.com

查看本地邮箱

mail

四、测试 SMTP 认证(关键)

1. 安装测试工具

sudo apt install swaks

2. 测试 SMTP 认证(587)

swaks --to user@yourdomain.com \
      --from user@yourdomain.com \
      --server mail.yourdomain.com \
      --port 587 \
      --auth \
      --tls

✅ 收到 250 OK 表示认证成功


五、收信测试(IMAP / POP3)

1. 使用 openssl 测试 IMAPS

openssl s_client -connect localhost:993

登录:

a login user@yourdomain.com password
a select inbox
a logout

2. 使用 mutt 测试(推荐)

sudo apt install mutt
mutt -f imaps://user@yourdomain.com@localhost

六、发信到外网(真实投递测试)

1. 发给 Gmail / QQ / 163

echo "test" | mail -s "test" xxx@gmail.com

2. 查看日志

tail -f /var/log/mail.log

重点看:

  • status=sent
  • 是否被拒收(4xx / 5xx)

七、检查 DNS 与反垃圾配置(非常重要)

1. MX 记录

dig MX yourdomain.com

2. SPF

dig TXT yourdomain.com

示例:

"v=spf1 mx ~all"

3. DKIM

dig TXT default._domainkey.yourdomain.com

4. DMARC

dig TXT _dmarc.yourdomain.com

八、测试 TLS / SSL

1. 证书检查

openssl s_client -connect mail.yourdomain.com:465

2. 测试 TLS(587)

swaks --server mail.yourdomain.com --port 587 --tls

九、反垃圾与反病毒(如已安装)

SpamAssassin

spamassassin -D --lint

ClamAV

clamdscan test.eml

十、常见问题排查

邮件发不出去

tail -n 50 /var/log/mail.log

被 Gmail 拒收

  • 没有 DKIM / SPF
  • IP 在黑名单
  • 使用动态 IP

用户无法登录

  • 检查 dovecot 认证方式
  • 检查邮箱路径权限

十一、推荐测试组合(最省事)

一键测试 SMTP + TLS + 认证

swaks --to test@gmail.com --server localhost --port 587 --tls --auth

收信测试

mutt -f imaps://user@domain.com@localhost

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

  • 你用的是 Postfix + Dovecot 还是 Exim
  • 是否 公网服务器
  • 是否 已配置 SSL / DKIM

我可以给你一份 针对你环境的精确测试清单

0