How-To

Cloudflare Pages MailChannels plugin: "Could not send your email" fix

The Cloudflare Pages MailChannels plugin shows "Could not send your email. Please try again." because its request to MailChannels is rejected, and the free Workers sending it relied on is no longer available. DNS changes won't bring it back. Replace the plugin with a Pages Function that calls an email provider's HTTP API.

Sohail HussainSohail Hussain8 min read

Short answer

  • The plugin demo shows this message for any failed call to MailChannels, so the text does not tell you the cause. In current setups the usual cause is that the free MailChannels route for Cloudflare Workers no longer works.
  • Stop debugging DNS and replace the plugin with a Pages Function that calls an email provider's HTTP API with your own API key. It takes about 20 lines, and the code is below.

You deployed the @cloudflare/pages-plugin-mailchannels demo or your own copy of it. You submit the form and get Could not send your email. Please try again. People report a 401 when running locally and a 512 once deployed to Cloudflare. Either way, no mail arrives.

Why it happens

That sentence is the demo's generic failure text. It is not an SMTP reply and not a Cloudflare error code. The plugin posts your message to MailChannels, and if that call fails for any reason, the form shows the same line.

Here are the causes, most common first.

  1. The free Workers sending path is gone. The plugin relied on a free arrangement where requests coming from Cloudflare's network could send through MailChannels without an account or API key. Reviews and community reports say Cloudflare discontinued the MailChannels integration for Workers. I could not confirm the current terms from an official page in this rewrite, so check MailChannels' own site before relying on any part of it. If that free path is gone, every submission fails no matter what you fix.
  2. Domain Lockdown is missing. In 2022 and 2023 the same error often came from a missing TXT record at _mailchannels on your domain.
  3. SPF does not authorize MailChannels. Old threads also mention an SPF record without the MailChannels include.
  4. You are running locally. With wrangler pages dev the request does not originate from Cloudflare's network, so a local 401 is expected for a route that depended on that origin.

About the 512 status: I can't point you to a documented meaning for it, so don't spend time decoding it. Treat it as "the upstream call failed."

Checking causes 2 to 4 is harmless, and your SPF should be valid anyway (the SPF generator can build one). But if the free path has ended, fixing them will not bring it back.

How to tell which cause you have

SymptomLikely causeWhat to do
Error on every submission, even on a clean preview deploymentFree route endedSwitch to an email API
Error only with wrangler pages devLocal run is not on Cloudflare's networkTest on a deployed preview
Worked in 2022 or 2023, broke later without a code changeFree route endedSwitch to an email API
New provider returns 403 or 422 in logsUnverified domain or mismatched fromVerify the domain, match the address
Mail accepted but lands in spamSPF, DKIM or DMARC alignmentFix authentication records

Fix: send through an email API from a Pages Function

Any provider with an HTTP API works. The example uses Resend's endpoint. Postmark, SendGrid and Mailgun have a similar shape, but check each provider's docs for field names and auth headers.

Step 1: Create the key and verify your domain

  1. Create an account with your provider and generate an API key with send-only permission if it offers that.
  2. Verify your sending domain by publishing the DNS records the provider gives you (SPF and DKIM at minimum). If you haven't done this before, see how to set up SPF, DKIM and DMARC.
  3. In your Pages project, open the Settings area for variables and secrets, and add EMAIL_API_KEY as an encrypted secret. Redeploy after adding it, because the value only reaches new deployments.

Step 2: Replace the plugin with a function

Remove the plugin from your functions/_middleware.js (or wherever you mounted it) and add functions/api/contact.js:

export async function onRequestPost({ request, env }) {
  const form = await request.formData();
  const name = String(form.get("name") || "").slice(0, 100);
  const email = String(form.get("email") || "").slice(0, 200);
  const message = String(form.get("message") || "").slice(0, 5000);

  if (!email || !message) {
    return new Response("Missing fields", { status: 400 });
  }

  const res = await fetch("https://api.resend.com/emails", {
    method: "POST",
    headers: {
      "Authorization": `Bearer ${env.EMAIL_API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      from: "Website <contact@example.com>",
      to: ["you@example.com"],
      reply_to: email,
      subject: `New message from ${name}`,
      text: message,
    }),
  });

  if (!res.ok) {
    console.log("Email API error", res.status, await res.text());
    return new Response("Could not send", { status: 502 });
  }
  return new Response("Sent", { status: 200 });
}

Point your form's action (or your fetch call) at /api/contact.

Do not use the visitor as the sender

Send from an address on the domain you verified and put the visitor's address in reply_to. Using the visitor's address as from fails SPF and DMARC checks, and most providers reject it.

Step 3: Deploy and read the logs

  1. Deploy, then submit the form from the deployed URL, not from a local server.
  2. Open your Pages project in the Cloudflare dashboard and view the function's real-time logs.
  3. Read the Email API error line. It shows the provider's actual status and message, which is what the plugin never showed you.

Step 4: Spam-proof the form

A public form that sends mail is an open target. Add a honeypot field or a CAPTCHA before you go live, and keep the field length limits in the code above. Otherwise bots will burn through your provider's quota.

Other routes and where they fall short

OptionGood forCatch
Provider HTTP API (above)Contact forms on Pages or WorkersOne secret and one verified domain to manage
Cloudflare Email WorkersForwarding and replying within Email RoutingAs I understand it, sends only to verified destination addresses; check Cloudflare's docs for current status
SMTP from the functionNothing hereMost SMTP libraries expect Node-style sockets that Workers do not provide
A hosted form serviceNo code at allAnother vendor in the path; free tiers may have limits

For a form that mails only you, the provider API is the simplest choice. An Email Worker is fine if its restrictions suit you.

Checklist before you try again

  • The plugin import and middleware are removed, so nothing still calls MailChannels.
  • EMAIL_API_KEY is set as a secret and the project was redeployed afterward.
  • Your sending domain shows as verified at the provider.
  • The from address is on that verified domain.
  • The visitor's address is in reply_to.
  • You are testing on a deployed URL and reading function logs.

If nothing works

Contact your email provider's support first, because they can see why a request was rejected. If you think the problem is on the Cloudflare side (the function never runs, or secrets don't arrive), use Cloudflare's support or developer channels. Include the exact status code and response body from your function log, the timestamp, the sending domain, and what you already tried.

Subject: API send from a Cloudflare Pages Function returns an error

Hi, I send a contact-form email from a Cloudflare Pages Function by
calling your HTTP API.

Domain: example.com (verified: yes/no)
From address: contact@example.com
Timestamp (UTC): 2026-11-30 14:05
Response status: 403
Response body: {paste the body from the function log}

Already checked: API key is set as a secret and the project was
redeployed; SPF and DKIM records are published.
What could cause this rejection?

Where Mailneo fits

Only a small part of this is ours to help with. Mailneo sends campaigns and newsletters through mailboxes and providers you connect; it is not an SMTP relay or a transactional email API for your own app. Business plan customers get a public REST API that can send campaigns, but I haven't validated it as a contact-form backend, so I wouldn't use it for that. Use a transactional provider for the form itself (see transactional vs marketing emails). If you later want to send newsletters or outreach to people who write in, that is where Mailneo makes sense.

Common questions

Can I still use the MailChannels plugin with an API key?

I can't verify that from the sources I had. If you want to stay with MailChannels, read its current documentation for authenticated sending and call it from a function yourself. The old plugin itself was built around the keyless route.

Why does it work on my machine but not deployed, or the reverse?

Local and deployed runs send from different networks, and a route that depends on Cloudflare's network behaves differently locally. With an API key you own, both environments behave the same, which is the main reason to switch.

Do I need a paid plan with the new provider?

That depends on the provider and your volume. Limits and prices change, so check the provider's pricing page; a low-traffic contact form is a small workload.

Why does my form mail land in spam after switching?

Usually the domain is verified but DMARC alignment is off, or from does not match the verified domain. Fix that first, then see how to avoid the spam folder.

technicalmailchannelscloudflareerror-codes
Share this article
Sohail Hussain

Sohail Hussain

Founder & CEO at Mailneo

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

Related Articles

How-To

ActiveCampaign n8n error 301 on create contact: causes and fixes

A 301 from the ActiveCampaign node means the request went to a URL that redirects, so start with the API URL in your n8n credential. Copy it from Settings, then Developer, and check the scheme and path. Zapier 403 and cURL error 28 behind Cloudflare have different causes, covered below.

Sohail Hussain|9 min read
How-To

"Stage not on allowlist": Apollo to HubSpot sync fix

The error "Stage not on allowlist" means the contact's Apollo stage is not on the list of stages permitted to push to HubSpot. Open the HubSpot integration in Apollo, go to the Sync tab, and add that stage under "Stages for push contacts". Lifecycle stage mapping is a separate setting.

Sohail Hussain|7 min read
How-To

Salesmate "Authorization with Gmail failed": Gmail IMAP fix

Salesmate shows "Authorization with Gmail failed" when it can't read your Gmail account over IMAP. In Gmail settings, enable IMAP, choose "Do not limit the number of messages in an IMAP folder", and show All Mail in IMAP. Then reconnect the account in Salesmate. Other causes are covered below.

Sohail Hussain|8 min read
How-To

AWeber export "Stop Status" and "Stop Time" columns explained

In an AWeber subscriber export, a non-empty Stop Time and a non-zero Stop Status most likely mean the person has stopped receiving your mail, usually because they unsubscribed. AWeber doesn't explain the columns in the file, so verify against a few known unsubscribes, then import those rows as blocked, not subscribed.

Sohail Hussain|7 min read

Ready to supercharge your email marketing?

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

Get Started Free