Files
cloudflare_temp_email/vitepress-docs/docs/en/guide/feature/subdomain.md
majorcheng 1a7cfb8c95 feat: 支持创建邮箱 API 的子域名后缀匹配开关 (#929)
* feat: 支持创建邮箱 API 的子域名后缀匹配开关

* fix: 修复 review 提到的开关三态与域名校验问题

* fix: 补充域名归一化与子域名匹配回归测试

* fix: 修复后台开关跟随 env 回退与 account_settings 半成功保存

* fix: 收口账号设置刷新提示与子域名状态重复读取

* fix: 拦截超长域名并透传账号设置刷新失败
2026-04-04 00:11:23 +08:00

2.2 KiB

Configure Subdomain Email

::: warning Note Subdomain emails may not be able to send emails. It is recommended to use main domain emails for sending and subdomain emails only for receiving.

Mail channel is no longer supported. The reference below is limited to the receiving part only. :::

Reference

Create Random Second-level Subdomain Addresses

If your base domain mail routing is already configured, you can also let users create mailbox addresses with an automatically generated random second-level subdomain, for example:

  • Base domain: abc.com
  • Created address: name@x7k2p9q1.abc.com

This is useful for mailbox isolation and reducing repeated hits on the same address.

Add these worker variables:

RANDOM_SUBDOMAIN_DOMAINS = ["abc.com"]
RANDOM_SUBDOMAIN_LENGTH = 8
  • RANDOM_SUBDOMAIN_DOMAINS: base domains that allow optional random second-level subdomains
  • RANDOM_SUBDOMAIN_LENGTH: random string length, range 1-63, default 8

Note

This feature only appends a random second-level subdomain when the mailbox is created.

It does not automatically create Cloudflare-side subdomain mail routes or DNS records for you, so make sure the base-domain/subdomain routing is already available first.

Let APIs Specify Subdomains Directly

If you do not want the system to generate a random subdomain, and instead want the caller to explicitly create addresses like team.abc.com, enable:

ENABLE_CREATE_ADDRESS_SUBDOMAIN_MATCH = true

When this is enabled, as long as abc.com is in the allowed base-domain list, the following addresses can be created through /api/new_address or /admin/new_address:

  • name@team.abc.com
  • name@dev.team.abc.com

Note

This only relaxes the domain validation used by the create-address APIs. It does not change the default domain dropdown, and it does not create Cloudflare-side subdomain mail routes for you.

If the admin panel has already saved an override once, you can switch it back to Follow Environment Variable to clear the override and return to env fallback behavior.