设置域名电子邮件记录有三个原因:
DNS 邮件记录的确切值取决于您的电子邮件提供商。如果遇到问题,请查看故障排除并联系您的电子邮件服务提供商以确认 DNS 记录是否正确。
若你只需接收邮件,Cloudflare 提供 Email Routing,可免费将邮件转发到自定义邮箱地址。
若要从你的域名发送和接收邮件,你需要 SMTP 提供商。然后,在 Cloudflare 中创建两条 DNS 记录,步骤如下:
-
从你的 SMTP 提供商获取 IP 地址和 MX 记录详情(各厂商指南)。
-
添加
A或AAAA记录,指向邮件服务器 IP 地址的邮件子域。Type(类型) Name(名称) IPv4 address(IPv4 地址) Proxy status(代理状态) A mail192.0.2.1DNS only API 示例
At least one of the following token permissions is required:Required API token permissions
DNS Write
Create DNS Recordbash curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records" \ --request POST \ --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \ --json '{ "type": "A", "name": "mail.example.com", "content": "192.0.2.1", "ttl": 3600, "proxied": false }'Responsejson { "result": { "id": "<ID>", "zone_id": "<ZONE_ID>", "zone_name": "example.com", "name": "mail.example.com", "type": "A", "content": "192.0.2.1", "proxiable": true, "proxied": false, "ttl": 3600, "locked": false, "meta": { "source": "primary" }, "comment": null, "tags": [], "created_on": "2023-01-17T20:37:05.368097Z", "modified_on": "2023-01-17T20:37:05.368097Z" }, "success": true, "errors": [], "messages": [] } -
添加
MX记录,指向该子域。Type(类型) Name(名称) Mail server(邮件服务器) TTL Priority(优先级) MX @mail.example.comAuto 5 API 示例
At least one of the following token permissions is required:Required API token permissions
DNS Write
Create DNS Recordbash curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records" \ --request POST \ --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \ --json '{ "type": "MX", "name": "example.com", "content": "mail.example.com", "priority": 5, "ttl": 3600 }'Responsejson { "result": { "id": "<ID>", "zone_id": "<ZONE_ID>", "zone_name": "example.com", "name": "example.com", "type": "MX", "content": "mail.example.com", "priority": 5, "proxiable": false, "proxied": false, "ttl": 3600, "locked": false, "meta": { "source": "primary" }, "comment": null, "tags": [], "created_on": "2023-01-17T20:54:23.660869Z", "modified_on": "2023-01-17T20:54:23.660869Z" }, "success": true, "errors": [], "messages": [] }
如果没有电子邮件认证记录,任何人都可以发送看似来自您域名的电子邮件——这种技术称为域名欺骗(domain spoofing)。为防止这种情况,您需要添加 DNS TXT 记录(域名 DNS 设置中基于文本的条目),使接收邮件服务器能够验证电子邮件是否确实来自您:
- 发件人策略框架(SPF) ↗:列出被授权代表您的域名发送电子邮件的 IP 地址和域名。
- 域名密钥识别邮件(DKIM) ↗:使用加密签名验证发件人域名,并确认电子邮件内容在传输过程中未被篡改。
- 基于域的消息认证、报告与一致性(DMARC) ↗:告知接收服务器当 SPF 或 DKIM 检查失败时该如何处理(例如,拒绝或隔离该电子邮件),并向您发送有关电子邮件流量的汇总报告。
有关如何设置电子邮件安全记录,请参阅安全记录。
默认情况下,Cloudflare 不代理端口 25(SMTP)上的电子邮件流量。仅当您为 SMTP 配置了 Spectrum 时,才能代理出站电子邮件。