Security

API key best practices

Short answer

Give each app or server its own key, named after where it lives. Use Sending only keys for anything that just sends, and lock them to one domain. Keep full-access keys for admin scripts. Store keys in environment variables or a secrets manager, never in code or the browser. Check Last used on the API keys page and revoke keys nobody uses. A revoked key stops working at once.

Last checked 16 November 2026

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

  1. 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.
  2. Sending only by default. A leaked sending key cannot read your logs, add domains or create more keys.
  3. Lock sending keys to a domain. A key for acme.com cannot then send from marketing.acme.com. See Domain-locked keys.
  4. Keep keys out of code. Use environment variables (MAILCANDOR_KEY) or your platform’s secrets store. Add .env to .gitignore.
  5. Server side only. Never put a key in browser JavaScript, a mobile app or a public repository.
  6. 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.
  7. 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.created and api_key.revoked record 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.

Questions

Can I see a key again after creating it?

No. The full key is shown once. Mailcandor stores only a hash of it. If you lose it, create a new key and revoke the old one.

Do API keys expire?

No. A key works until it is revoked. Review your keys regularly and revoke any you do not need.

Can I call the API from a browser or mobile app?

Do not. Anyone can read a key shipped to a browser or app. Call Mailcandor from your server.

Is the SMTP password a different secret?

No. The SMTP password is an API key, so the same rules apply. A sending-only key is enough for SMTP.

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.