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.
- Open API keys and press Create API key.
- Name it, for example “Client A production”.
- Under permission, choose Sending only.
- 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.)
- 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
fromon 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.comreceipts and another fornews.acme.comnewsletters. - 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_verifieduntil it is.
If it does not work
- “Only sending keys can be limited to one domain.” You asked for
permission: fullwith adomain_id. Usesending. - “No domain with this id on your team.” The
domain_idis wrong or from another team. - 403 restricted_api_key “This key can only send from …” Your
fromaddress 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.