Deliverability

Resend works locally but not in production: Next.js, Vercel fixes

Resend email that works in development but not in production usually comes down to one of five causes: an unverified sending domain, a missing RESEND_API_KEY on the host, a send that isn't awaited, a call made from the browser, or no server adapter on Astro. Check Resend's logs first.

Sohail HussainSohail Hussain10 min read

Short answer

  • Open the Resend Logs page first. If no request appears, your code never reached Resend: check that RESEND_API_KEY is set for Production in Vercel and redeployed, that the send is awaited on the server, and that the browser isn't calling Resend directly.
  • If requests appear but fail or only reach your own inbox, verify your sending domain in Resend and use a from address on it.

The symptom is the same on every stack: the contact form sends an email on localhost, and in production the form seems to work but nothing arrives. Nothing in the UI tells you why, because most of these failures are silent. The causes are the same whether you use Next.js on Vercel, Astro or Lovable; only the place where you fix them changes.

Resend is a developer transactional API, so this isn't a Mailneo problem. People on community forums report the same five mistakes again and again, and they are all fixable in minutes once you know which one you have.

Why it works locally and fails in production

Your laptop and your production host differ in four ways that matter here:

  • Environment variables. .env.local stays on your machine. Production only sees what you set in the host's dashboard.
  • Recipient. Your local test goes to your own address. Production goes to a stranger.
  • Process lifetime. A dev server keeps running. A serverless function can be frozen as soon as it returns a response.
  • Runtime. next dev and astro dev run server code for you. A production build may be static, or may have no server at all.

Here are the causes in the order I'd check them.

CauseSymptomFix
API key missing in productionNo request in Resend Logs; 401 or invalid key error in function logsAdd RESEND_API_KEY to Production, redeploy
Domain not verifiedRequest appears but is rejected, or only your signup address receives mailVerify the domain, send from it
Send not awaitedIntermittent or no emails; function returns 200await the send and check error
Called from the browserCORS error; request to api.resend.com in network tabMove the call to a route, action or function
Astro without server adapter404 or 405 on the endpoint in productionAdd the Vercel adapter, disable prerender

Step 1: read the Resend logs

Before you change anything, open Logs in the Resend dashboard. It splits the problem in two.

  • No request at all. Your code never reached Resend. Go to the key, await, browser and Astro fixes below.
  • A request with an error. Read the message. A key problem and a domain problem look different.
  • A request marked delivered, but nobody got it. Stop debugging the app. Check the spam folder and the recipient address, then paste the raw headers into the email header analyzer.

Exact status codes and wording can change, so treat the messages as a guide and trust what your own logs show.

Step 2: set RESEND_API_KEY in production

This is the most common cause when nothing shows up in the logs.

  1. Open your project in Vercel, then Settings > Environment Variables.
  2. Add RESEND_API_KEY with your key, and select the Production environment. Add Preview too if you test on preview deployments.
  3. Redeploy. Variables are read when a deployment is built, so an existing deployment won't see a new one.
  4. Check that the name matches your code exactly, including case.

Never prefix the key with NEXT_PUBLIC_. That bundles it into browser code and exposes it.

Silent failures happen because process.env.RESEND_API_KEY is just undefined when missing. Validate the environment at startup so a missing key fails loudly:

import { z } from "zod";

const env = z
  .object({
    RESEND_API_KEY: z.string().startsWith("re_"),
  })
  .parse(process.env);

export default env;

Now a missing or malformed key throws a clear error in your logs instead of a mystery later.

Preview is not Production

Vercel scopes variables per environment. A key that works on a preview deployment can still be missing from Production, so check the environment checkboxes on each variable.

Lovable

On Lovable, the key has to live in the project's backend secrets or server-side function configuration, never in front-end code. Lovable's interface changes often, so look for its secrets or integrations settings rather than trusting a fixed click-path. People on Lovable's community forum report trouble connecting Resend, usually because the key or the call ended up on the client side.

Step 3: verify your sending domain

This one fools people because it looks fine in development. Until you verify a domain, Resend lets you send from its shared testing address (onboarding@resend.dev), and only to the email address you signed up with. Your local test, sent to yourself, succeeds. Production sends to a real visitor and is rejected.

  1. In Resend, open Domains and add your domain, or a subdomain such as mail.example.com. I'd use a subdomain so your main domain's reputation stays separate.
  2. Add the DNS records Resend shows you at your DNS host. They include SPF and DKIM records; copy them exactly, because the values are specific to your account.
  3. Click verify and wait. DNS changes can take minutes to a few hours.
  4. Change your from address to one on that domain:
from: "Contact Form <hello@example.com>"

If the domain already has an SPF record for another sender, don't publish a second one. A domain must have only one SPF TXT record, so merge the mechanisms. The SPF generator helps with that, and how to set up SPF, DKIM and DMARC covers the full picture.

The from domain must match

Verifying example.com does nothing if your code still sends from a different domain or from the testing address. Compare the from value in production with the domain shown as verified.

Step 4: await the send and check the error

On serverless platforms, a function can be frozen or ended once the response returns. If you fire the request and respond immediately, the send may never complete. A long-running dev server hides this completely.

Broken:

export async function POST(req: Request) {
  const { name, message } = await req.json();
  resend.emails.send({ from, to, subject: "New message", text: message }); // not awaited
  return Response.json({ ok: true });
}

Fixed:

export async function POST(req: Request) {
  const { name, message } = await req.json();
  const { data, error } = await resend.emails.send({
    from: "Contact Form <hello@example.com>",
    to: ["you@example.com"],
    subject: `New message from ${name}`,
    text: message,
  });

  if (error) {
    console.error("Resend error", error);
    return Response.json({ error: error.message }, { status: 500 });
  }
  return Response.json({ id: data?.id });
}

Two details matter. The Resend Node SDK returns { data, error } rather than throwing on API errors, so a rejected send still counts as success for await unless you check error. And returning 200 no matter what hides every failure from your form. Surface the error, and log it so it shows in your host's runtime logs.

If you want to respond before the send finishes, use your framework's supported way of running work after the response (for example after in recent Next.js versions, or waitUntil from Vercel's functions package). Check the current docs for your version before relying on either.

Step 5: keep Resend out of the browser

Calling the Resend API from a client component, or from front-end code in Lovable or a plain React app, produces a CORS error. It would also expose your secret key. Resend's API isn't meant to be called from browsers.

Move the call to a server boundary:

  • Next.js App Router: a Route Handler (app/api/contact/route.ts) or a Server Action marked "use server".
  • Next.js Pages Router: a file under pages/api/.
  • Lovable or other SPA setups: a server-side function, with the browser calling your function rather than Resend.

If your browser's network tab shows a request going to api.resend.com, that's the bug. Rotate the key too if it was ever shipped in client code.

Step 6: add a server runtime for Astro on Vercel

Astro builds static output by default. A form endpoint in src/pages/api/contact.ts needs server rendering, or it won't run in production even though astro dev handles it fine.

  1. Install the Vercel adapter with npx astro add vercel.
  2. Make sure the endpoint opts out of prerendering. Depending on your Astro version and output mode, that's export const prerender = false; in the endpoint file, or output: "server" in astro.config.mjs. Check the Astro docs for your version.
  3. Read the key with import.meta.env.RESEND_API_KEY in server code, and set it in Vercel as in Step 2.

If your POST request to the endpoint returns 404 or 405 in production, this is your cause.

Checklist before you try again

  • The Resend Logs page shows a request for your latest test.
  • RESEND_API_KEY exists in Vercel under Production, and you redeployed after adding it.
  • The key has no NEXT_PUBLIC_ prefix.
  • The domain shows as verified in Resend, and from uses it.
  • The send is awaited, and your code checks error.
  • The browser network tab shows a call to your own route, not api.resend.com.
  • You tested to an address that isn't your Resend signup email.

If nothing works

Contact Resend support from the dashboard. If the problem is the deployment itself (variables not applying, function errors), use Vercel's support or your host's. Include the email ID from the logs, the timestamp with timezone, the from domain, the exact error text, and what you already tried.

Subject: Contact form emails send locally but not in production

Hi,

Emails sent through the Resend API work in development but not in production.
- Sending domain: example.com (status in dashboard: verified)
- Example email ID: {email-id-from-logs}
- Timestamp (UTC): {timestamp}
- Error returned by the SDK: {exact error text}
- Host: Vercel, Production environment, RESEND_API_KEY set and redeployed
- Already checked: await on send, server-side call, from address on verified domain

Can you tell me why this request was rejected or not delivered?

Prevent it next time

  • Send a test from a Preview deployment before launch, to an address that isn't your own signup email.
  • Keep the env schema check so a missing key breaks the build or boot.
  • Always check error from the SDK result.
  • Add a rate limit or bot check to the contact form; open endpoints get abused.

Common questions

Why do I get no error at all?

Because the SDK returns errors instead of throwing, and an unawaited call never reports its result. Log the error object and await the call.

Can I test with onboarding@resend.dev in production?

Only to the address you signed up with. Anything else needs a verified domain.

Do I need a separate API key for production?

Not required, but a separate key per environment makes rotation and debugging easier. Whichever you choose, the production deployment must have its own copy of the variable.

Emails now send but land in spam. What next?

That is a deliverability problem, not a code problem. Check that SPF and DKIM pass in the message headers, and read how to avoid the spam folder.

deliverabilityresendvercellovable
Share this article
Sohail Hussain

Sohail Hussain

Founder & CEO at Mailneo

Building Mailneo — AI-powered email marketing for growing businesses.

Related Articles

Deliverability

Password reset and welcome emails in spam with SPF, DKIM, DMARC passing

Passing SPF, DKIM and DMARC proves who sent a message, not that Gmail trusts it. Transactional mail still lands in spam when the domain is new, links are tracked through a shared domain, the HTML is malformed, or the message looks like marketing. Check these causes in order.

Sohail Hussain|9 min read
Deliverability

Resend Account Suspended With No Explanation: Next Steps

If Resend suspended or rejected your account with no explanation, do three things in parallel: send support a specific appeal with evidence of your sending practices, route critical mail through a second provider today, and fix the likely abuse trigger. Expect no detailed reason from the review.

Sohail Hussain|9 min read
Deliverability

Supabase auth emails in Outlook spam and blocked by Yahoo

Supabase auth emails sent from a subdomain often fail at Outlook and Yahoo while Resend works, because the two paths differ in sending infrastructure, DKIM domain and reputation. Read the headers, send auth mail through your authenticated provider over custom SMTP, and give the subdomain steady, low-complaint volume.

Sohail Hussain|11 min read
Deliverability

0x800ccc0e: Outlook Unable to Connect to SMTP Server, Fixed

Outlook error 0x800ccc0e means the app could not open a connection to your outgoing (SMTP) server. Usually the port, encryption setting or password is wrong, or antivirus, a firewall or your ISP is blocking it. Set port 587 with STARTTLS, turn on SMTP authentication, and test again.

Sohail Hussain|10 min read

Ready to supercharge your email marketing?

Start sending smarter emails with AI-powered campaigns. No credit card required.

Get Started Free