IMAP 与 POP3
imap、pop3s;收信协议。
25 分钟
IMAP 与邮件收取协议
IMAP(Internet Message Access Protocol)让邮件客户端 在服务器上同步文件夹、标记已读、搜索历史——适合多设备(手机 + 电脑)场景。POP3 则倾向「下载到本地后删除服务器副本」,适合单设备。运维邮箱、告警归档、工单系统通常用 IMAP。本课衔接 dnm-smtp,端口与 TLS 见 networking-essentials,DNS MX 见 dns-essentials,服务器见 linux-essentials,配置管理见 git-essentials。
学习目标
- 对比 IMAP vs POP3 的行为差异与选型
- 说出 IMAP 端口 143 / 993 及 TLS 配置
- 用
openssl或curl测试 IMAP 登录与会话
IMAP vs POP3
| IMAP | POP3 | |
|---|---|---|
| 邮件存储 | 服务器为主 | 下载到本地 |
| 多设备同步 | ✅ 文件夹/已读同步 | ❌ 易冲突 |
| 端口 | 143 / 993 | 110 / 995 |
| DevOps 场景 | 运维共享邮箱、归档 | 单节点拉取日志邮件 |
IMAP 993 会话
Client ──TLS──► Dovecot:993
Client: SELECT INBOX
Client: FETCH 1 BODY[]
Server: 返回邮件正文(留在服务器)
端口与加密
| 端口 | 说明 |
|---|---|
| 143 | 明文 IMAP,可 STARTTLS 升级 |
| 993 | IMAPS,隐式 TLS(生产推荐) |
# 测试 IMAPS 连接
openssl s_client -connect imap.example.com:993 -quiet
# a1 LOGIN ops@example.com password
# a2 LIST "" "*"
# a3 SELECT INBOX
# a4 FETCH 1 ENVELOPE
# a5 LOGOUT
Dovecot 最小配置(示意)
/etc/dovecot/dovecot.conf 或 conf.d/10-mail.conf:
protocols = imap pop3
mail_location = maildir:~/Maildir
ssl = required
ssl_cert = </etc/letsencrypt/live/mail.example.com/fullchain.pem
ssl_key = </etc/letsencrypt/live/mail.example.com/privkey.pem
/etc/dovecot/conf.d/10-auth.conf:
disable_plaintext_auth = yes
auth_mechanisms = plain login