Security

How to lock an API key to one domain

Short answer

A domain-locked key is a sending-only API key that can send only from one domain on your team. Create it under API keys with Sending only and Limit to one domain, or POST /v1/api-keys with permission sending and a domain_id. Sending from any other domain answers 403 restricted_api_key. Full-access keys cannot be locked, and deleting the domain deletes its locked keys.

Last checked 16 November 2026

If you send from several domains, for example your product, a client’s brand and a newsletter subdomain, a domain-locked key makes sure each app can only send as its own domain. If one key leaks, the others are safe.

Create a locked key in the dashboard

You need the Admin or Developer role.

  1. Open API keys and press Create API key.
  2. Name it, for example “Client A production”.
  3. Under permission, choose Sending only.
  4. In Limit to one domain, pick the domain. (The field only appears for sending-only keys. Leave it empty for Any domain on this team.)
  5. Press Create key and copy the key. It is shown once.

The API keys list shows the locked domain in the Domain column. Unlocked keys show Any domain.

Create a locked key with the API

Use a full-access key. Find the domain’s id first:

curl https://api.mailcandor.com/v1/domains \
  -H "Authorization: Bearer $MAILCANDOR_ADMIN_KEY"

Then create the key:

curl https://api.mailcandor.com/v1/api-keys \
  -H "Authorization: Bearer $MAILCANDOR_ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Client A production",
    "permission": "sending",
    "domain_id": "8c0e4f6a-2b1d-4e3f-9a7b-5c6d7e8f9a0b"
  }'

The 201 answer includes token, the key. GET /v1/api-keys lists each key’s domain_id.

What the lock does

  • A send with from on the locked domain works as normal.
  • A send from any other domain is refused before anything is stored:
{ "error": { "type": "restricted_api_key", "message": "This key can only send from acme.com." } }

with status 403. Over SMTP the same refusal comes back as 550 5.7.1.

  • The key is still sending-only: it cannot read logs, add domains or create keys.

The lock checks the domain of the from address exactly. If you send from hello@mail.acme.com, add and verify mail.acme.com as its own domain and lock the key to that.

Good uses

  • Agencies and platforms sending for several clients: one locked key per client domain.
  • Separate streams: a key for acme.com receipts and another for news.acme.com newsletters.
  • Third-party tools such as a CMS or form plugin: give each a key locked to the one domain it needs.

Things to know

  • You cannot change a key’s domain. Create a new key and revoke the old one.
  • Deleting a domain deletes the keys locked to it. Anything using those keys gets 401 invalid_api_key. Create new keys before you delete a domain you still send from.
  • The domain must be verified to send. You can lock a key to a domain that is not verified yet, but sends from it answer 403 domain_not_verified until it is.

If it does not work

  • “Only sending keys can be limited to one domain.” You asked for permission: full with a domain_id. Use sending.
  • “No domain with this id on your team.” The domain_id is wrong or from another team.
  • 403 restricted_api_key “This key can only send from …” Your from address uses a different domain. Fix the address or use the right key.
  • 401 after deleting a domain. Its locked keys were deleted with it. Create a new key.

See API key best practices and the API reference.

Questions

Can I lock a full-access key to a domain?

No. Only sending-only keys can be limited to one domain. The API answers 422 if you try.

Can I change which domain a key is locked to?

No. Create a new key locked to the other domain, switch your app to it, and revoke the old one.

Does the lock cover subdomains?

No. The from address's domain must be exactly the locked domain. mail.acme.com and acme.com are different domains.

Does the lock apply over SMTP?

Yes. SMTP sends go through the same checks, so a locked key used as the SMTP password can only send from its domain.

Related

Send with someone on your side.

Unlimited domains on every plan, a person before any block, and 3,000 emails a month free. Tell us what you send and we set you up within one business day.