An API key can send email as your domains. Treat it like a password for your business.
The two kinds of key
| Kind | Can do | Use it for |
|---|---|---|
| Sending only | Send (/v1/emails, /v1/emails/batch), check drafts (/v1/emails/check), /v1/whoami, the SendGrid and Postmark compatible send endpoints, and SMTP. Can be locked to one domain. |
App servers, workers, SMTP in apps, CMS plugins. |
| Full access | Everything the API allows: domains, keys, webhooks, logs, suppressions, reviews, usage, audit log. | Admin scripts and automation you control. |
Sending only is the default when you create a key in the dashboard. Pick it unless you need more.
Seven habits
- One key per place. “Production web”, “Billing worker”, “Staging”. If one leaks you revoke one key, not all of them. Names can be up to 50 characters.
- Sending only by default. A leaked sending key cannot read your logs, add domains or create more keys.
- Lock sending keys to a domain. A key for
acme.comcannot then send frommarketing.acme.com. See Domain-locked keys. - Keep keys out of code. Use environment variables (
MAILCANDOR_KEY) or your platform’s secrets store. Add.envto.gitignore. - Server side only. Never put a key in browser JavaScript, a mobile app or a public repository.
- Check Last used. The API keys page shows Last used for each key (updated at most once a minute). A key that says Never or was last used months ago can usually go.
- Revoke when people leave. Removing someone from the team does not revoke their keys. Revoke the keys they made.
Create a key the safe way
In the dashboard: API keys → Create API key → name it after where it will live → Sending only → pick a domain under Limit to one domain → Create key. Copy the key straight into your secrets store. It starts with mc_live_ and is shown once.
With the API (needs a full-access key):
curl https://api.mailcandor.com/v1/api-keys \
-H "Authorization: Bearer $MAILCANDOR_ADMIN_KEY" \
-H "Content-Type: application/json" \
-d '{"name": "Production web", "permission": "sending", "domain_id": "'"$DOMAIN_ID"'"}'
The token in the 201 answer is the key. Only admins and developers can create keys, and a key made by someone who has since lost that role cannot create or revoke keys.
Check what a key is
curl https://api.mailcandor.com/v1/whoami -H "Authorization: Bearer $MAILCANDOR_KEY"
{ "team": "Acme", "key": "Production web", "permission": "sending" }
How Mailcandor protects keys
- Only a SHA-256 hash of each key is stored, so the full key cannot be shown again, even to us.
- Keys never appear in the audit log;
api_key.createdandapi_key.revokedrecord the name and permission only. - Every key belongs to one team, and the team’s rate limit applies to all its keys together.
If it does not work
- 401 invalid_api_key. The key was revoked or mistyped. See 401 invalid API key.
- 403 restricted_api_key on a non-send endpoint. It is a sending-only key. Use a full-access key for that call.
- 403 restricted_api_key on a send. The key is locked to another domain.
- A key leaked. Follow Rotate a leaked key now.
See Security and the API reference.