DKIM 检查:查看您的 DKIM 记录
DKIM 让发信服务器用私钥为每封邮件签名,接收方则用发布在 DNS 中的公钥来验证签名。输入您的域名和邮件服务商使用的选择器来获取这个公钥,然后查看它的长度、格式,以及签名可能失败的原因。
如何找到您的 DKIM 选择器
一个域名可以同时拥有多个 DKIM 密钥,分别用于不同的服务或密钥轮换,而选择器就是指明使用哪一个的标签。每个密钥都位于 selector._domainkey.yourdomain.com,所以 google._domainkey 和 s1._domainkey 可以并存。
最快的查找办法:给自己发一封邮件,打开完整的邮件头,查看 DKIM-Signature 这一行。其中 s= 的值是选择器,d= 是签名的域名。
不确定结果是什么样子?上方的示例按钮分别展示了健康的 2048 位密钥(yahoo.com,选择器 s2048)、会触发弱密钥警告的 1024 位密钥(yahoo.com,选择器 s1024),以及已吊销的密钥(gmail.com,选择器 20230601)。
部分服务商默认使用的选择器
这些会因服务商和账户的设置方式而异,所以请把它们当作起点,并向您的服务商确认。
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=example.com; s=selector1; h=from:to:subject:date:message-id; bh=BASE64-BODY-HASH...; b=BASE64-SIGNATURE...
| 服务商 | 常见选择器 |
|---|---|
| Google Workspace | google(较新的密钥使用以日期命名的选择器) |
| Microsoft 365 | selector1 和 selector2 |
| SendGrid | s1 和 s2 |
| Mailchimp | k1、k2 和 k3 |
| 许多控制面板和主机商 | default |
如何阅读 DKIM 记录
| 标签 | 含义 |
|---|---|
| v=DKIM1 | 版本。可选,但如果存在则必须为 DKIM1 |
| k | 密钥类型:rsa(默认)或 ed25519 |
| p | base64 编码的公钥。值为空表示该密钥已被吊销 |
| t=y | 测试模式:接收方可能对验证失败比较宽容 |
| t=s | 严格:签名域名必须与 From 域名完全一致 |
| s | 该密钥可用于哪些服务:email 或 * |
密钥长度、拆分与轮换
- 请使用 2048 位的 RSA 密钥。1024 位的密钥仍可通过验证,但已不再推荐,更短的则不安全。
- 2048 位的密钥比单个 DNS 字符串能容纳的 255 个字符更长,所以会作为同一条 TXT 记录中的多个带引号字符串发布。大多数 DNS 管理后台会自动替您处理。如果密钥被截断了,就无法读取。
- 请不时轮换密钥。先发布新的选择器,让邮件服务商改用它来签名,并把旧选择器保留到已在传输途中的邮件投递完毕。
- 要停用某个密钥,请发布 p= 为空的记录,让用它生成的签名干净地失败,而不是让记录凭空消失。
dig +short TXT selector1._domainkey.example.com "v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA..." "...IDAQAB" nslookup -type=TXT selector1._domainkey.example.com Resolve-DnsName -Name selector1._domainkey.example.com -Type TXT dig +short CNAME selector1._domainkey.example.com selector1-example-com._domainkey.tenant.example.net.
Selectors some providers use by default
These vary by provider and by how an account was set up, so treat them as a starting point and confirm with your provider.
| Provider | Common selectors |
|---|---|
| Google Workspace | google (and a date-based name for newer keys) |
| Microsoft 365 | selector1 and selector2 |
| SendGrid | s1 and s2 |
| Mailchimp | k1, k2 and k3 |
| Many control panels and hosts | default |
Reading a DKIM record
| Tag | Meaning |
|---|---|
| v=DKIM1 | The version. Optional, but it must be DKIM1 if present |
| k | Key type: rsa (the default) or ed25519 |
| p | The public key, in base64. An empty value means the key is revoked |
| t=y | Testing mode: receivers may be lenient about failures |
| t=s | Strict: the identity in i= must be in the same domain as d=, not a subdomain |
| s | Which services the key may be used for: email or * |
Key types and sizes
| Key | Length of p= value | How the tool rates it |
|---|---|---|
| RSA under 1024 bits | Under about 216 characters | Problem: too weak to trust |
| RSA 1024 bits | About 216 characters | Warning: still verifies, 2048 is recommended |
| RSA 2048 bits | About 392 characters | Good |
| Ed25519 | 44 characters (32 bytes) | Good if exactly 32 bytes after decoding |
RFC 8301 sets the floor at 1024 bits for signers and recommends at least 2048. Ed25519 keys, defined in RFC 8463, are short and fast, but some receivers do not verify them yet, so a sender that uses Ed25519 usually signs with an RSA key as well. The lengths above are approximate because they depend on how the key is encoded.
Key size, splitting and rotation
- Use a 2048-bit RSA key. 1024-bit keys still verify but are no longer recommended, and anything shorter is unsafe.
- A 2048-bit key is longer than the 255 characters one DNS string can hold, so it's published as several quoted strings inside one TXT record. Most DNS dashboards do that for you. If a key gets truncated instead, it can't be read.
- Rotate keys from time to time. RFC 6376 sets no schedule, so pick an interval you will actually keep. Publish a new selector first, switch your mail provider to sign with it, and leave the old selector in place until mail already in transit has been delivered.
- To retire a key, publish the record with an empty p= so signatures made with it fail cleanly instead of the record vanishing.
When the key is fine and DKIM still fails
A published key only means receivers can fetch it. The Authentication-Results header on a failed message says what happened, and the wording differs between receivers, but the cases below are the usual ones.
| Result on the message | Usual meaning |
|---|---|
| dkim=none | The message carried no DKIM-Signature. Signing is not switched on for this sender |
| dkim=fail, body hash mismatch | The body changed after signing: a footer, a disclaimer, or re-encoding by a gateway or mailing list |
| dkim=fail, signature did not verify | The DNS key does not match the private key in use, often after a key was regenerated but not republished |
| dkim=permerror or no key | The name in s= and d= has no usable record: a typo, a wrong domain, or a truncated key |
| dkim=pass but dmarc=fail | The signature is valid but d= is not the From domain, so it does not align |