Join our Newsletter — 33% off our NHI Course
Home› Guides› SendGrid, Mailgun and Mailchimp API Keys Security Guide:…
Guide Secrets Management

SendGrid, Mailgun and Mailchimp API Keys Security Guide: Scopes, Sending Keys and Abuse Detection

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, edited by Lalit Choda Updated 27 October 2026 12 min read
On this page

A leaked email delivery API key lets an attacker send mail as your organisation, from your authenticated domains and with your sender reputation, so phishing sent with it passes SPF, DKIM and DMARC checks that your recipients rely on. SendGrid, Mailgun and Mailchimp keys are created by developers and marketing teams, pasted into web applications, WordPress plugins and CRM integrations, and rarely appear in a secrets inventory. Most default to full account access, which also exposes contact lists, suppression data and message logs. This guide explains how each platform's keys, roles and restrictions work, how to scope keys to sending only, how to detect a leak or abuse, and how to respond. It is written for application security, email and messaging owners and secrets management teams. For the general SaaS key lifecycle see the SaaS API Token Security Guide; this page covers what is specific to email delivery platforms.

Key takeaways

  • Email keys are impersonation keys. Mail sent through your account carries your domain's DKIM signature, so domain authentication proves the mail came from your provider account, not that you sent it.
  • Use the narrowest key each platform offers. SendGrid Custom Access keys, Mailgun Domain Sending Keys and Mailgun RBAC roles can all be limited; Mailchimp Marketing and Transactional keys carry full account access, so isolate them by integration.
  • Restrict by network where you can. SendGrid IP Access Management covers the UI, API and SMTP relay, and Mailgun supports an API IP allowlist.
  • The formats are detectable. GitHub secret scanning has push protection and validity checks for SendGrid, Mailgun and Mailchimp keys, and Gitleaks has rules for each.
  • Volume and destination are the abuse signals. Sudden sending spikes, new recipient domains, rising bounces and complaints, and campaigns nobody scheduled are how stolen keys show up.

How identity and access work on email delivery platforms

All three platforms separate the human login (with two-factor authentication and, on higher plans, single sign-on) from the API keys that applications use. The key types differ more than their names suggest.

PlatformKey typeAccessHow it is sentNotes from vendor docs
Twilio SendGridAPI key: Full AccessAll endpointsAuthorization: BearerShown once; limit of 100 keys per account; a key cannot exceed its creator's permissions
Twilio SendGridAPI key: Custom AccessEndpoints and access levels you choose (for example Mail Send only)Authorization: BearerUse for every application
Twilio SendGridBilling Access, Email Address Validation AccessBilling endpoints only; validation endpoints plus read access to reportingAuthorization: BearerBilling calls need their own key
MailgunPrimary account / account API keyFull CRUD on all endpoints and all sending domainsHTTP Basic, username apiShown once
MailgunDomain Sending KeyPOST to /messages and /messages.mime for one domain onlyHTTP BasicCreated under the domain's sending keys settings
MailgunRBAC keyAdmin, Developer, Analyst or Support roleHTTP BasicEnterprise and some Business plans; role fixed at creation
MailchimpMarketing API keyFull account access, limited by the creating user's roleAPI key with data centre suffixShown once; keys created on or after 22 June 2026 expire after one year
MailchimpTransactional (Mandrill) keyFull Transactional account access"key" field in the JSON bodyShown once; treat like a password

Two behaviours matter for offboarding. On Mailchimp, revoking a user's access removes the API keys that user generated, which protects against leavers but can break integrations a leaver set up; create integration keys from a dedicated, documented user. SendGrid's documentation does not say that removing a teammate deletes the keys they created, so check the key list and delete them explicitly when someone leaves. SMTP is a parallel path: SendGrid's SMTP relay authenticates with an API key as the password, and Mailgun SMTP credentials are separate secrets per domain, so inventory both.

Admin roles and privileged access

PlatformRolePrivilege levelControl
SendGridAdmin teammateFull access, can create other admins, manage teammates and billing, impersonate subusersTwo or three named people; SSO where the plan allows
SendGridRestricted teammate (Developer, Marketer, Accountant presets or custom)Only the features grantedDefault for staff and agencies
SendGridRead-only teammateView onlyAuditors and support
MailgunAdminFull administrative access to all endpointsRestrict; prefer Developer for engineers
MailgunDeveloper, Analyst, SupportTechnical endpoints; read-only metrics; mostly read with some management writesMatch role to job
MailchimpAdminCan see API keys other users generatedReview key list quarterly
MailchimpManagerCan generate own API keysLimit who holds Manager
  • Enforce 2FA for every login: SendGrid password teammates set up 2FA during onboarding, subusers set up their own, and once 2FA is on SendGrid stops accepting username and password Basic authentication for API calls. The 2020 wave of hacked SendGrid accounts, sold and used to send phishing that many organisations' filters let through, came from cracked and reused passwords.
  • Use SSO for large teams: SendGrid SSO teammates are available on Pro and Premier plans and can be limited to specific subusers.
  • Separate tenants: SendGrid subusers and Mailgun subaccounts let you split brands or business units so one key cannot send for every domain.

Integrations, API tokens and service accounts

Choosing the right key

Use caseSendGridMailgunMailchimp
Application sends transactional mailCustom Access key with Mail Send onlyDomain Sending Key for that domainTransactional key in its own account or subaccount
Reporting or analytics toolCustom Access, read-only statsRBAC Analyst keyKey created by a user with a limited role
Infrastructure automation (domains, webhooks)Custom Access with the specific settings scopesRBAC Developer keyDedicated integration user
Third-party plugin or SaaS connectorSeparate Custom Access key per pluginDomain Sending KeyOne named key per integration

Where keys leak

  • Web and CMS plugins: SMTP and mailer plugins store provider keys in the CMS database and settings screens. The Gravity SMTP CVE-2026-4020 case exposed stored mail API keys and SMTP passwords through an unauthenticated REST endpoint, with Mailgun credentials confirmed leaked at one host.
  • Front-end code and mobile apps: Mailchimp explicitly does not support client-side CORS calls or embedding keys in mobile apps. Any key in a browser bundle is public.
  • Repositories and environment files: SendGrid's docs recommend an environment variable named SENDGRID_API_KEY and warn against committing keys; scanners still find them in .env files and sample code.
  • The provider itself: in the Mailchimp breach attackers used a hijacked internal support tool to obtain customer API keys, which Mailchimp then disabled, and affected customers' lists were used for phishing. Per-integration keys make that kind of forced revocation survivable.
  • Screenshots and tickets: Mailchimp notes that blurring a key in a screenshot or video is not enough.

Store keys in a secrets manager and inject them at run time; see the Secrets Management Guide. The Twilio Credentials Security Guide covers the wider Twilio account, which SendGrid accounts may sit under when using Twilio Unified Login.

Webhooks are credentials too

Event webhooks deliver bounces, opens and inbound mail to your endpoints. Mailgun signs each webhook: concatenate the timestamp and the 50-character token, compute an HMAC-SHA256 with your webhook signing key, and compare the hex digest with signature. Mailgun recommends caching tokens to reject replays, optionally rejecting stale timestamps, and its webhook requests carry a TLS client certificate with the Common Name webhooks.mgsend.net. A leaked signing key lets an attacker forge events, for example fake unsubscribes or bounces, so store it with the API keys.

Logging and detection

Secret scanning coverage

CredentialGitHub secret typePush protectionValidity checkGitleaks rule and anchor
SendGrid API keysendgrid_api_keyYesYessendgrid-api-token, prefix SG.
Mailgun API keymailgun_api_keyYesYesmailgun-private-api-token, key- followed by 32 hex characters near the word mailgun
Mailgun SMTP credentialmailgun_smtp_credentialNo (public repositories only)NoNone specific
Mailgun webhook signing keyNonen/an/amailgun-signing-key
Mailchimp API keymailchimp_api_keyYesYesmailchimp-api-key, 32 hex characters plus a data centre suffix such as -us12
Mailchimp Transactional keymandrill_api_keyNo (public repositories only)NoNone specific

Only the SendGrid key has a fixed prefix; Mailgun and Mailchimp rules rely on nearby keywords, so keys stored under neutral variable names can be missed. Add custom patterns or a generic high-entropy rule; see the Generic API Key Detection Guide and the Git Secret Scanning Guide.

Abuse signals

  • Sending volume: hourly sends per key or sending domain against a baseline; abuse is usually bursty and out of hours.
  • Recipients and content: new recipient domains, mail to large free-mail lists, and new templates or campaigns nobody scheduled.
  • Deliverability: sharp rises in bounces, spam complaints and blocklist hits, and DMARC aggregate reports showing your provider's IPs sending unusual volume for your domain.
  • Configuration changes: new API keys, new teammates, new sending domains, changed webhook URLs and IP allowlist changes.
  • Access attempts: SendGrid's IP Access Management shows recent access attempts, including blocked ones.

DMARC aggregate reporting is the external control: the DMARC, SPF and DKIM Guide explains how to read it and how to keep provider include records limited to the providers you actually use.

Metrics: number of full-access keys in use (target zero for applications); share of keys mapped to an owner and integration; keys older than the rotation period (Mailgun suggests at least quarterly, Mailchimp at least yearly); mean time from leak alert to revocation; share of accounts with IP restrictions enabled.

Hardening baseline

  1. Inventory: list every key, SMTP credential, webhook signing key and teammate across all accounts, subusers and subaccounts, with owner and integration. Remove keys with no known user.
  2. Enforce login security: 2FA for every user, SSO where available, two or three admins only.
  3. Reissue narrow keys: for each integration create a SendGrid Custom Access key, a Mailgun Domain Sending Key or RBAC key, or a dedicated Mailchimp key. Deploy, confirm sends succeed, then delete the old key. SendGrid and Mailchimp cannot restore a deleted or revoked key, so keep the old key until the new one is proven, and use a staging subuser or domain to test first.
  4. Restrict networks: enable SendGrid IP Access Management or the Mailgun IP allowlist for fixed egress addresses. Add the administrator's own IP first: SendGrid warns that removing it can lock you out and that recovery needs identity verification through support.
  5. Segment domains: send marketing and transactional mail from different subdomains and accounts so one key cannot send as the corporate domain.
  6. Turn on detection: push protection, scanning of CMS databases and backups, and alerts on sending spikes and configuration changes.
  7. Rotate on a schedule and on every staff change for anyone who could see keys.

Small organisations with one website and a newsletter should at least use a sending-only key for the site, 2FA on every login and push protection. Larger organisations should centralise provider accounts, ban full-access keys in applications by policy and monitor sending through the SOC.

Leak response

  1. Delete or revoke the key at the provider immediately; deleting it in the plugin or application alone does nothing.
  2. Review sends since the earliest possible exposure: recipients, templates, links and volume. If phishing went out, warn recipients and your own users.
  3. Check for persistence: new keys, teammates, sending domains, webhook URLs and changed suppression lists.
  4. Issue a narrow replacement, then rotate any SMTP credential and webhook signing key stored in the same place.
  5. Follow the Phishing Incident Response Playbook where malicious mail was delivered.

Framework mapping

Control areaNIST SP 800-53 Rev 5NIST CSF 2.0ISO/IEC 27001:2022 Annex AMITRE ATT&CK
Key inventory, scope and rotationIA-5, AC-6PR.AA-01, PR.AA-05A.5.17 Authentication informationT1552.001 Credentials In Files
Admin and teammate accessAC-2, IA-2PR.AA-05A.8.2 Privileged access rightsT1586.002 Email Accounts
Network restrictionAC-17 Remote AccessPR.AA-05A.8.20 Networks securityT1078.004 Cloud Accounts
Sending and configuration monitoringSI-4, AU-6DE.CM-09A.8.16 Monitoring activitiesT1566 Phishing

Common misconfigurations

  • Full Access or account keys in web applications: a site that only sends password resets holds a key that can export contacts and create new keys.
  • One key shared across plugins, environments and agencies: revocation becomes an outage, so it is postponed.
  • Keys stored only in the CMS: plugin vulnerabilities and database backups expose them; nobody rotates them because nobody knows they exist.
  • Logins without 2FA: a cracked password gives the attacker the console and the ability to mint fresh keys.
  • Unverified webhooks: endpoints that accept unsigned events can be fed forged bounces and unsubscribes.
  • Over-broad SPF and DKIM delegation: leftover provider records let any account on a provider you no longer use send as your domain.

Practitioner checklist

  • Inventory keys, SMTP credentials and webhook signing keys across all accounts, subusers and subaccounts.
  • Replace application keys with SendGrid Custom Access (Mail Send) keys or Mailgun Domain Sending Keys.
  • Create one named Mailchimp key per integration from a dedicated user, and track the one-year expiry.
  • Require 2FA for all users and SSO where the plan allows; keep admins to a named few.
  • Enable SendGrid IP Access Management or the Mailgun IP allowlist for fixed egress IPs.
  • Verify every webhook signature and reject replayed tokens.
  • Enable push protection and scan CMS databases, backups and front-end bundles for keys.
  • Alert on sending spikes, new keys, new teammates and new sending domains.
  • Remove SPF includes and DKIM records for providers you no longer use.

Standards and references

Related NHI Mgmt Group resources: SaaS API Token Security Guide · Email Authentication for Developers Guide · API Key Management Guide · Email Identity and BEC Guide

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Researched and written by the NHI Mgmt Group editorial team using AI tools, under the editorial direction of Lalit Choda. Facts are drawn from the sources listed on this page and checked by our automated quality process. Last updated 27 October 2026. Spotted an error? Use our contact page.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM and Agentic AI security. nhimg.org

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick the PDF box to continue.