Guide · Email API keys · Updated
Is My Resend Key Safe in My Frontend? Keep Resend and SendGrid Email Keys Out of Your Lovable, Bolt and v0 App
Email keys are quiet leaks. Nothing breaks, but anyone who copies your Resend or SendGrid key can send email as you, from your own domain. That can get your domain flagged as spam and your sending paused. Here is what Resend, SendGrid and Lovable say, why you keep seeing a CORS error, where the key should live, one trap that bites even when the key is hidden, and how to check your live app.
1. The rule: email keys never go in the browser
Email providers have no public key that is safe to show. Every Resend and SendGrid API key is secret.
| Provider | Key looks like | Usual server name | Safe in the browser? |
|---|---|---|---|
| Resend | re_... | RESEND_API_KEY | No |
| SendGrid (Twilio) | SG.... (two dots) | SENDGRID_API_KEY | No |
| Lovable Resend connector | managed by the connection | none in your code | Never in the browser; Lovable keeps it server-side |
- Resend: do not expose your API key in the browser or other client-side code. A leaked key lets anyone send from any domain you verified, use your monthly quota and damage your sending reputation. Resend keys do not expire on their own.
- SendGrid: in a browser-only app the key has to be in the JavaScript, anyone can read it, and anyone with it can make API calls as you. Never put the key in your code or a public repo.
- Lovable:
RESEND_API_KEYis a backend secret. Anything starting withVITE_is built into the browser code, so never use that prefix for it.
Sources: Resend: How to handle API keys · Resend: How to handle a leaked API key · SendGrid: CORS · SendGrid: API keys · Lovable: Secrets
2. The CORS error is a warning sign
If your AI builder tried to send email straight from a React component, you probably saw something like blocked by CORS policy ... api.resend.com/emails. That error is on purpose:
- Resend says CORS errors usually happen when you send from the client side, and the fix is to send from the server so you do not expose your key.
- SendGrid does not allow browser calls to its
v3/mail/sendendpoint at all, for the same reason.
Here is the catch. The send failed, but the key may still be in your code. AI builders often leave it in a VITE_RESEND_API_KEY variable or a test file, or add a quick proxy that still ships the key. So a CORS error you "fixed" is a good reason to check your live JavaScript. See which env vars end up in the browser.
Sources: Resend: How to fix CORS issues · SendGrid: Cross Origin Resource Sharing
3. Where the key should live (Lovable, Bolt, v0, Cursor)
- Lovable: store the key as the backend secret
RESEND_API_KEY. Lovable says Secrets are encrypted, injected into your Edge Functions and never reach the browser. Or use Lovable's Resend connector. Resend says a Sending access key is enough for an app that only sends email. - Bolt and other Supabase apps: send from a Supabase Edge Function that reads
RESEND_API_KEYwithDeno.env.get, and set the key in Edge Function secrets before you deploy. - v0, Cursor and other Next.js apps: send only from a Route Handler (like
app/api/send/route.ts) or a Server Action. Use an env var withoutNEXT_PUBLIC_. - SendGrid on any host: store it as a server env var like
SENDGRID_API_KEY. Give it Custom (restricted) access with only Mail Send, not Full Access.
Sending to real users? Resend's test address onboarding@resend.dev only delivers to the Resend account owner. Verify your own domain in Resend and ask your builder to use it in the "from" address, then redeploy the function.
Sources: Lovable: Secrets · Lovable: Connect your app to Resend · Resend: Send with Supabase Edge Functions · Supabase: Sending emails · SendGrid: API key permissions
4. The open contact form trap
Moving the key to the server is step one. But many AI-built email functions take to, subject and html straight from the browser. Then a stranger can skip your form and call the function directly, sending spam or phishing to anyone, from your verified domain. They never see your key.
- Set the recipient on the server. A contact form should only ever email your own inbox. If you email a signed-in user, take their address from the server session.
- Set "from" and the subject on the server.
- Treat the message as plain text so nobody can inject links or HTML into your emails.
- Add a limit per visitor or per user, and require sign-in where it makes sense.
This matters because inbox providers judge your domain by what it sends. Resend says accounts must stay under a 4% bounce rate and a 0.08% spam rate, or sending may be paused.
VibeCheck does not call or test your email functions. Check this one by hand, or use the prompts below.
5. Check your live app in 60 seconds
Only check apps you own or have permission to test.
- Fastest: paste your live link at the top of this page. VibeCheck reads your homepage and the JavaScript files it loads and flags Resend (
re_) and SendGrid (SG.) keys. It masks any key it finds. - By hand in Chrome: open your live site, right-click → Inspect, then press Ctrl+Shift+F (Cmd+Option+F on Mac). Search for
re_,SG.,api.resend.comandapi.sendgrid.com. - Send your contact form once. In the Network tab, look at the request. It should go to your own server function, not to
api.resend.comorapi.sendgrid.com. Then check the request body: if it includes atoaddress, your function may be the open trap from section 4.
6. Found a key? Do this now
- Resend: open the API keys page, click More options next to the key, then Remove API key. Deleting a key revokes it right away. Make a new key (Sending access) and deploy it.
- Check what was sent. In Resend, filter the Logs page by that key and check the Emails page for recipients you do not know. Resend keeps 30 days of activity.
- SendGrid: delete the key in Settings → API Keys (you can revoke a key at any time), make a new Mail Send only key, and check your email activity.
- Move the send to the server (section 3), redeploy, and scan your live site again to confirm the key is gone.
More detail for every key type: I leaked my API key. What do I do now?
Sources: Resend: Delete the key first · SendGrid: API keys
7. Copy-paste fix prompts
Paste the matching prompt into Lovable, Bolt, v0, Replit or Cursor. After you deploy, delete any email key that was ever in client code and use a new one.
Search this whole project for re_, SG., RESEND_API_KEY, SENDGRID_API_KEY, api.resend.com and api.sendgrid.com. Remove every email provider key from client-side code and from any NEXT_PUBLIC_, VITE_ or EXPO_PUBLIC_ variable. Move every email send into a server function (Supabase Edge Function, Next.js Route Handler or Server Action) that reads the key from a server-side secret. The browser should only call my own server function. List every key you removed so I can delete it in Resend or SendGrid and make a new one.
Update my email server function: set the "to" address on the server (my own inbox for the contact form) and ignore any "to", "from", "cc", "bcc" or "subject" sent from the browser. Set "from" to my verified domain on the server. Treat the visitor's name and message as plain text (escape any HTML). Reject messages longer than 5,000 characters. Add a limit of 5 sends per visitor per hour and return 429 when it is hit. If the email goes to a signed-in user, get their address from the server session, not from the request. Show me the changed code.
Send all email in my app from a backend edge function. Store my Resend key as the backend secret RESEND_API_KEY (or use the Resend connector), never in code or a VITE_ variable. Use my verified domain in the "from" address, not onboarding@resend.dev. Remove any Resend key from my frontend files and .env.
8. Check it for me
Paste your link into VibeCheck. In about 10 seconds it checks the JavaScript your live site sends to visitors for leaked keys (Resend, SendGrid, OpenAI, Stripe sk_live_, Supabase service_role and more), checks if your public Supabase key can read open tables, and checks security headers, SEO basics and broken links.
It is a public, read-only check. It never asks for your code, your login or your email accounts.
Pricing: the problems list is free (just add your email). The $9 fix report gives you a copy-paste fix prompt for every problem found, or get the $29 10-pack (10 fix reports to use any time). No subscription.
No tool can promise your app is 100% secure. VibeCheck catches common, costly mistakes before a stranger does.
9. FAQ
Is it safe to put my Resend API key in my frontend?
No. Resend says not to expose your API key in the browser or other client-side code. The key is the only thing needed to send through your account, so anyone who copies it can send email from any domain you verified, use up your monthly quota and hurt your sending reputation. Send email from a server function instead.
Why do I get a CORS error when I send email with Resend or SendGrid?
Because the email is being sent from the browser. Resend says CORS errors usually mean you are sending from the client side, and SendGrid does not allow browser calls to its mail send endpoint. The fix is not a CORS workaround. Move the send into a server function, so the key stays secret.
Where should my Resend key go in Lovable?
In a backend secret, not in code or a VITE_ variable. Lovable says Secrets are encrypted, injected into your Edge Functions and never reach the browser, and lists RESEND_API_KEY as a backend secret. Lovable also has a Resend connector that keeps the key out of your app code.
Is a SendGrid API key safe in browser code?
No. SendGrid says a browser-only app has to embed the key, anyone can read it in the JavaScript, and anyone with it can make API calls as you. Keep it in a server environment variable like SENDGRID_API_KEY and give it only the Mail Send permission.
My key is on the server now. Can my contact form still be abused?
Yes, if your email function lets the browser choose who gets the email and what it says. Then anyone can call it and send spam or phishing from your domain. Set the "to" address on the server (your own inbox for a contact form), require sign-in or a limit per visitor, and treat the message as plain text.
How do I check if my live app leaks an email key?
Paste your live link into VibeCheck for a free scan. It reads the JavaScript your homepage loads and flags Resend keys (re_) and SendGrid keys (SG.). You can also open DevTools, press Ctrl+Shift+F (Cmd+Option+F on Mac) and search your loaded files for re_, SG. and api.resend.com.
More questions? See the VibeCheck FAQ. Related guides: How to check if your API key is exposed · Is my Twilio Auth Token safe? (texts and SMS codes) · I leaked my API key. What do I do now? · Is NEXT_PUBLIC_ safe for API keys? · Is my OpenAI key safe? · Is my Stripe key safe? · Is my Lovable app safe? · Is my Bolt app secure? · Is my v0 app secure? · Vibe coding security checklist.