跳转到内容
搜索文档

设置电子邮件记录

最后更新 查看 MarkdownAgent 设置

设置域名电子邮件记录有三个原因:

DNS 邮件记录的确切值取决于您的电子邮件提供商。如果遇到问题,请查看故障排除并联系您的电子邮件服务提供商以确认 DNS 记录是否正确。


接收邮件

若你只需接收邮件,Cloudflare 提供 Email Routing,可免费将邮件转发到自定义邮箱地址。

发送和接收邮件

若要从你的域名发送和接收邮件,你需要 SMTP 提供商。然后,在 Cloudflare 中创建两条 DNS 记录,步骤如下:

  1. 从你的 SMTP 提供商获取 IP 地址和 MX 记录详情(各厂商指南)。

  2. 添加 AAAAA 记录,指向邮件服务器 IP 地址的邮件子域。

    Type(类型) Name(名称) IPv4 address(IPv4 地址) Proxy status(代理状态)
    A mail 192.0.2.1 DNS only
    API 示例

    Required API token permissions

    At least one of the following token permissions is required:
    • 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": []
    }
  3. 添加 MX 记录,指向该子域。

    Type(类型) Name(名称) Mail server(邮件服务器) TTL Priority(优先级)
    MX @ mail.example.com Auto 5
    API 示例

    Required API token permissions

    At least one of the following token permissions is required:
    • 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 设置中基于文本的条目),使接收邮件服务器能够验证电子邮件是否确实来自您:

配置电子邮件安全记录

有关如何设置电子邮件安全记录,请参阅安全记录

代理 SMTP 流量

默认情况下,Cloudflare 不代理端口 25(SMTP)上的电子邮件流量。仅当您为 SMTP 配置了 Spectrum 时,才能代理出站电子邮件。

这篇文档对您有帮助吗?