Your email API key is in your website's code. Delete it before someone sends spam as you.
Last reviewed November 1, 2026 against the providers' current documentation.
The short version
Delete the key now. SendGrid: Settings → API Keys, open the action menu next to the key, Delete API Key, then Confirm. Resend: on the API keys page, More options → Remove API key. Then check what was sent with it (SendGrid's Activity feed, Resend's Logs and Emails pages), look for API keys or teammates you didn't add, and move the code that sends email into a server function that reads a new, send-only key from a server-only environment variable. Neither key expires by itself, so it keeps working until you delete it.
Why it matters
An email API key is a login to your sending account. With it, anyone can send email from the domain you verified, so their phishing or spam goes out under your name, through your authenticated domain, and counts against your plan and your sender reputation. Spam complaints and bounces from those messages can get your sending paused, which stops your own password resets and receipts. A SendGrid Full Access key reaches every API endpoint on the account, and a Resend Full access key can create, delete, read and update any resource. Resend's docs say its keys don't expire and stay valid until you delete them; SendGrid's API keys page doesn't describe any expiry either.
Fix it, in this order
Find which key it is
SG.followed by two dot-separated parts is a Twilio SendGrid key;re_is a Resend key. Search your code and hosting settings for where it's set, usuallyVITE_SENDGRID_API_KEY,VITE_RESEND_API_KEYor aNEXT_PUBLIC_variable, and note every app that uses the same key: they will all need the new one.Delete the key
SendGrid: Settings → API Keys, click the action menu for the key, choose Delete API Key and click Confirm; SendGrid then rejects calls made with it (its API docs note a short propagation delay). Resend: open API keys, find the key (the page shows when each key was last used), then More options → Remove API key. Resend's leaked-key article says to delete first, which revokes the key immediately, and then create the replacement. If a live service depends on the key, create the new key, deploy it to the server, then delete the old one within minutes.Check what was sent
SendGrid: click Activity in the console and search by recipient, subject or event type; SendGrid's account-takeover guidance says to look for unrecognized API keys, unknown sending addresses, unusual subject lines and unexpected domains. The feed holds a limited history unless you have the Email Activity history add-on (up to 30 days), so look now. Resend: the Logs page filtered by API key and date shows each request with its body, and the Emails page shows recipients, subjects and delivery results; Resend keeps 30 days of activity.Clean up the account
A full-access key may have been used to change things that outlive it. On SendGrid, check Settings → API Keys for keys you didn't create and Settings → Teammates for people you don't know, and delete them; turn on Settings → Two-Factor Authentication; and consider Settings → IP Access Management, which blocks every IP you haven't added (its Recent Access Attempts list shows who tried). SendGrid notes the pending mail queue may be cleared during account cleanup, so resend important emails. On Resend, look through your API keys, domains and webhooks for anything you didn't add. Then contact the provider's support with the key, the time window and what you've done.Watch your sender reputation
Recipients who got the attacker's mail will mark it as spam, and those addresses go on your suppression list. Resend asks you to keep bounce rate under 4% and spam rate under 0.08% and to watch its Metrics page for several weeks, because going over can pause sending. In SendGrid, watch the same numbers in your stats. If your domain sent phishing, a DMARC record with reporting helps you see who sends as you; AppInspected's $19 report checks SPF and DMARC.Send email from a server, with a send-only key
Both providers say to keep keys out of client-side code (SendGrid: treat the key like a password; Resend: don't expose it in the browser). Put sending behind a small server endpoint (an API route, a Server Action, a Supabase Edge Function, a Cloudflare Worker) that reads the key from a server-only environment variable, decides the recipient itself or checks it, rate-limits requests and adds a CAPTCHA to public forms, so the endpoint can't become an open relay. Create the new key with the least access: in SendGrid, Custom Access with only themail.sendscope; in Resend, Sending access limited to one domain. Rebuild and deploy, then run the check again: old builds can stay in caches, which is why deleting comes first.
Or ask your AI tool to do it
Paste this into Lovable, Bolt, Cursor, Claude Code or whichever tool built your app. Review what it changes before you deploy.
My website's frontend JavaScript contains an email API key (a SendGrid key starting with SG. or a Resend key starting with re_). Find every place the key is defined or read, including .env files and any VITE_, NEXT_PUBLIC_, REACT_APP_ or EXPO_PUBLIC_ variable, and every place that sends email (@sendgrid/mail, the resend package, fetch calls to api.sendgrid.com or api.resend.com). Move all sending into a server-side endpoint (API route, server action, Supabase Edge Function or serverless function) that reads the key from a server-only environment variable. The endpoint must not let the browser choose arbitrary recipients, senders or HTML: for a contact form, send only to my own address with the visitor's message as text; for account emails, look up the recipient on the server from the logged-in user. Validate input, rate-limit by IP and user, and add a CAPTCHA to public forms. Make sure no email API key or email SDK is included in the client bundle. Finally, remind me to delete the old key and create a send-only key (SendGrid Custom Access with mail.send only, or Resend Sending access limited to my domain).
How this happens
Usually a contact form, waitlist or "email me my results" button that an AI coding tool wired up from the page. Email SDKs want a key, so the tool puts it in a VITE_ or NEXT_PUBLIC_ variable to get rid of an undefined error, and that copies it into the JavaScript every visitor downloads. Sometimes the browser call doesn't even work, but the key is still in the bundle. A shared email.ts imported by both server and client code does the same.
Check that it's really fixed
After you deploy, run the free check. It reads your live site the way an attacker would and tells you if any secret key is still visible.
Topic check: Exposed API key checker
Find the other leaks before someone else does
The free check reads your home page and its scripts. The website security report goes through up to 30 pages and 40 JavaScript files, plus .env and .git files, security headers, cookies and CORS, domain and email records, and libraries with known vulnerabilities. Every finding comes with the fix for your host and a prompt for your AI tool.
$19 once, including 20 runs over 30 days so you can fix things and check again.

Questions
Is it enough to remove the key from my code?
No. Old copies of your JavaScript stay in browser caches, CDN caches and web archives, and the key works until you delete it in SendGrid or Resend. Delete it first, then deploy the clean code.
My key only has send permission. Is that still a problem?
Yes. A send-only key is exactly what a spammer wants: they can send phishing from your verified domain, and the complaints land on your account and can get your sending paused. It does limit the cleanup: a send-only key can't create new keys, read your contacts or change settings.
Can I make an email API key safe to use in the browser?
No. Anything in your JavaScript can be copied, and a domain-restricted key still sends from your domain. Keep the key on a server and expose only an endpoint that sends the specific emails your app needs.
I deleted the key. Do I need to do anything else?
Check the activity logs for mail you didn't send, remove API keys, teammates, domains or webhooks you didn't add, and watch your bounce and spam rates for a few weeks. If the logs show messages to your users, warn them that those emails weren't from you.
Does your check try the key?
No. The free check is passive: it finds SG. and re_ keys in your page and its JavaScript, shows them cut short, and never sends them to SendGrid or Resend. Only your provider's dashboard can tell you whether the key is still active and what it sent.
Sources
- Twilio SendGrid: API Keys (permissions, delete, shown once)
- Twilio SendGrid API: Delete API keys
- Twilio SendGrid API: API key permissions (mail.send)
- Twilio SendGrid: Email Activity Feed
- Twilio support: Proactive steps after an account takeover on SendGrid
- Resend: API keys (remove, last used, logs)
- Resend: How to handle a leaked API key
- Resend: How to handle API keys
- Resend changelog: API key permissions (Full access, Sending access)