New guide: how to warm up a dedicated IP without hurting your reputation. Read now →
Log in
MigoSMTP
SMTP and APIUpdated 14 Oct 2026

API Key Security: Permissions, Storage, Rotation and Leak Response

An email API key or SMTP credential that leaks can be used to send spam in your name within minutes, which damages your domain and IP reputation. This guide shows how to give each key only the permissions it needs, where to store it, how to rotate it without downtime and what to do in the first hour after a leak.

JL
Written by Jonas Lindqvist
Security Engineer
Reviewed by Karan Malhotra
  • Published4 Aug 2026
  • Read time4 min
  • Length761 words
Share this guide

API key security comes down to four habits: give every key the smallest set of permissions it needs, keep it in a proper secret store, rotate it without downtime and have a plan ready for the day one leaks. A leaked sending key lets anyone email as you, so it puts your sender reputation at risk as well as your data.

1key per app and environment
90 dayscommon rotation interval
< 1 hourtarget time to revoke a leaked key

Check the permission names in your account. The permission names in this guide are examples of the pattern. Use the options your MigoSMTP account actually offers, and choose the narrowest one that works.

Why keys leak

How it leaksExamplePrevention
Committed to a repositoryA config file with a key is pushed to a public or shared repoUse environment variables, ignore files and secret scanning
Shipped to the clientA key inside JavaScript or a mobile appCall your own server instead
Shared in chat or ticketsA key pasted in a support threadShare through a secret manager and rotate if exposed
Left on a departing accountA former contractor still holds the keyRotate when people leave
Logged by accidentA debug log prints request headersMask secrets in logs
Compromised serverMalware reads environment variablesPatch servers and limit what each server can reach

Step 1: One key per application and environment

Create separate keys for production, staging and every application that sends mail. Name them so you can recognise them in an audit log.

Key nameUsed byPermission
shop-productionThe online store, order emailsSend only
shop-stagingTest environmentSend only, to test addresses
crm-productionThe CRM, campaign sendingSend and manage own contacts
webhooks-readerA reporting jobRead events only
ops-adminA named person, rare tasksFull access with two-factor authentication

Step 2: Apply least privilege

Ask of each key: what is the least it needs to do? Sending mail does not require reading your contact list, changing DNS or managing billing, and a reporting job should not be able to send at all.

  • Prefer a send-only key for any system that only delivers messages.
  • Keep account, billing and user management for people with two-factor authentication, not for keys.
  • Review permissions each quarter and remove what is no longer needed.
  • If your account offers restrictions by IP address, domain or rate limit, use them. See the account security settings for what is available.

Step 3: Store keys safely

Load the key at runtime from the environment or a secret manager. A minimal pattern is below.

# .env  (never commit this file)
MIGOSMTP_API_KEY=replace-with-your-key

# .gitignore
.env
*.pem
<?php
$key = getenv('MIGOSMTP_API_KEY');
if (!$key) {
    throw new RuntimeException('API key is not configured');
}

Add secret scanning. Turn on secret scanning in your code host and run a scanner in your build pipeline. It catches keys before they reach a shared branch and gives you an alert if one slips through.

Step 4: Rotate without downtime

  1. Create the new key. Give it the same permissions and a name with the date or version.
  2. Store it. Add it to your secret manager or environment configuration.
  3. Deploy. Release the change and restart the services that read the key.
  4. Verify. Check delivery logs to confirm that traffic uses the new key.
  5. Revoke the old key. Do this only after traffic has moved. Wait a short period and check for failures.
  6. Record it. Note the date, the reason and who did it.

Step 5: Monitor for abuse

SignalWhat it can meanAction
Volume far above normalA leaked key or a loop in your codePause the key and investigate
New or unfamiliar recipientsSpam or phishing sent with your keyRevoke the key and review messages
Sending at unusual hoursAutomated abuseCheck the source IP and restrict access
Rising bounces or complaintsBad recipients or abuseCheck suppression and sources, see the spam checklist
Requests from new IP addressesA key used outside your serversAdd an allow list and rotate

If a key leaks: the first hour

MinutesDo this
0 to 10Revoke the key. If you cannot deploy a replacement yet, accept a short outage over continued abuse
10 to 30Create and deploy a new key. Confirm normal sending
30 to 60Review the delivery log for messages you did not send. Check complaint and bounce rates and blocklists
AfterFind out how it leaked, remove the source, rotate related secrets and write down what you learned

If mail was sent in your name, follow the blocklist removal guide and contact support so that the account review has context.

Think a key was exposed? Revoke it first, then contact us with the key name and the time so we can help you review recent sending.

Contact support

Further reading and sources

Frequently asked questions

Why is an email API key so sensitive?

Anyone who holds a sending key can send mail as you. Attackers use leaked keys to send phishing and spam within minutes, which can get your domain and IP blocklisted and your account suspended. The cost is in reputation, and that takes weeks to repair.

What does least privilege mean for API keys?

It means each key can do only what its job needs and nothing more. A key used by a web form to send mail should not be able to read contacts, change domains or manage billing. If it leaks, the damage is limited to what that key was allowed to do.

Should I use one key for everything?

No. Use a separate key for each application and environment. If one leaks you revoke only that key, and your logs show which system a message came from. Shared keys make incident response slow and risky.

Where should I store API keys?

Use environment variables or a secret manager, and load them at runtime. Do not put keys in source code, in the front end of a website or mobile app, in public repositories, in tickets or in chat. Add configuration files that hold secrets to your ignore file.

How often should I rotate keys?

A common rule is every 90 days for production keys, and straight away when a person with access leaves, a laptop is lost or a leak is suspected. More important than the interval is that you have a rotation process you have already practised.

How do I rotate a key without downtime?

Create a new key, add it to your secret store, deploy the change, confirm that traffic uses the new key and only then revoke the old key. Never revoke first, because that causes an outage while you deploy.

What should I do if a key is leaked?

Revoke the key immediately, create a replacement, deploy it, review recent sending for messages you did not send, and check for blocklist listings and complaint spikes. Then find out how it leaked and close that path.

How can I tell that a key is being abused?

Look for sudden volume, new or unusual recipients, sending at odd hours, a rise in bounces or complaints, and requests from unfamiliar IP addresses. Alerts on volume and bounce rate give you early warning.

Are SMTP credentials different from API keys?

They serve the same purpose, which is proving that you may send, and they need the same care. Treat the SMTP username and password like an API key: one set per application, stored as a secret and rotated on a schedule. See the SMTP settings guide for connection details.

Can I put an API key in a mobile app or in JavaScript on a web page?

No. Anything shipped to a device or browser can be extracted. Send mail from your own server, and let the app or page call your server, which then calls the email API with the key.

Topics#api keys#security#permissions#rotation#credentials#secrets
Was this guide helpful?Your answer helps us improve our documentation.

Start sending in minutes.

Create an account, add your domain and send your first email.

Start free Talk to sales