Tutorials

How to Send Emails from Cloudflare Workers for Free Using TypeScript

Cloudflare Workers Free can now send email without a separate SMTP server. Build a TypeScript Worker that sends notifications to a verified inbox, and learn which restrictions still apply.

Suppose you have a Cloudflare Worker that monitors a scheduled task. When the task finishes, you want to receive an email.

The message is simple: a subject, a few lines of text, and perhaps an error description if something went wrong.

You could integrate an external email provider, manage its API credentials, or configure an SMTP connection. But if the notification only needs to reach your own inbox, that is additional infrastructure for a fairly small task.

On November 24, 2026, Cloudflare announced that Email Sending is now available on the Workers Free plan.

Developers can send messages directly from Workers using a native binding:

await env.EMAIL.send({
  from: "[email protected]",
  to: "[email protected]",
  subject: "Build completed",
  text: "Your deployment finished successfully."
});

There is no separate SMTP server to configure inside the application.

The restriction is on who can receive the message.

Workers Free supports sending only to destination addresses verified in your Cloudflare account. Sending to arbitrary recipients requires Workers Paid.

For personal alerts, development notifications, and reports sent to your own team, that limitation may be perfectly acceptable.

In this tutorial, we’ll create a TypeScript Worker that sends an email to a fixed address through a protected HTTP endpoint.

1. Configure your sending domain

Before writing the Worker, Cloudflare needs to know which domain is authorized to send your messages.

Open the Cloudflare Dashboard and navigate to:

Compute → Email Service → Email Sending

Select Onboard Domain.

Content]: Configure your sending domain

Choose a domain already associated with your Cloudflare account.

Cloudflare Email Service requires the domain to use Cloudflare DNS. It prepares the necessary DNS records for email authentication, including SPF and DKIM, and handles bounce-routing configuration.

The setup may also involve a DMARC record.

These records matter because receiving email servers need a way to determine whether Cloudflare is authorized to send mail for your domain.

For example, if your domain is:

yourdomain.com

you could use the sender address:

[email protected]

The address is illustrative. Replace it with an address on a domain you control and have configured for Email Sending.

You do not need to create a conventional SMTP server merely to use that sender address.

However, configuring a domain is not the same as confirming that every message will reach an inbox. Spam filtering and recipient-side policies still apply.

Wait until Cloudflare reports that the sending domain is ready before testing the Worker.

2. Verify the destination address

This step is particularly important on the Free plan.

Cloudflare does not permit sending to arbitrary email addresses through Workers Free.

The recipient must be a verified destination address in your Cloudflare account.

Navigate to:

Compute → Email Service → Email Routing → Destination Addresses

Add the email address where you want to receive notifications.

For example:

[email protected]

Cloudflare sends a verification email to that inbox.

Open it and confirm the address.

Once verification is complete, the address becomes available for Email Sending.

Notice that the sender and recipient serve different purposes.

The sender belongs to the domain you have configured with Cloudflare.

The destination is an email address you control and have verified.

They do not need to use the same domain.

According to Cloudflare, sending to verified destination addresses is free on every plan and does not consume the ordinary daily or monthly sending quota.

That does not remove the responsibility to protect the Worker from unwanted requests.

3. Create a TypeScript Worker

Create a new project using Cloudflare’s project generator:

npm create cloudflare@latest -- email-alert-worker

When prompted, select a Hello World Worker with TypeScript.

Enter the project directory:

cd email-alert-worker

The generated project should contain a Wrangler configuration file and a TypeScript entry point, normally:

email-alert-worker/
├── src/
│   └── index.ts
├── wrangler.jsonc
└── package.json

The exact generated files can vary with the Cloudflare template version.

For this example, we only need the Worker entry point and its configuration.

4. Add the Email Sending binding

Open wrangler.jsonc and add the following configuration to the existing object:

{
  "send_email": [
    {
      "name": "EMAIL",
      "remote": true,
      "destination_address": "[email protected]"
    }
  ]
}

Do not replace the rest of the generated configuration. Keep the existing Worker name, entry point, compatibility date, and other project settings.

The properties have separate purposes.

name exposes the binding to the Worker as env.EMAIL.

remote: true allows local development to communicate with Cloudflare Email Service.

destination_address restricts this binding to one recipient.

That last option is particularly useful for a notification Worker.

Even if the code were accidentally changed to use another recipient, the binding would restrict where messages could be sent.

The destination address still needs to be verified in your account.

Cloudflare also supports sender allowlists and recipient allowlists through other binding configurations.

For this example, one fixed destination is sufficient.

5. Protect the notification endpoint

A Worker that sends email should not expose an unrestricted endpoint.

Consider this implementation:

export default {
  async fetch(request: Request, env: Env) {
    await env.EMAIL.send({
      from: "[email protected]",
      to: "[email protected]",
      subject: "Build completed",
      text: "Your deployment finished successfully."
    });

    return new Response("Email sent");
  }
};

The email-sending operation is valid.

But if deployed unchanged, any visitor who knows the Worker’s public URL could trigger it.

On a free subdomain such as workers.dev, that URL is still publicly accessible unless another access restriction has been configured.

A fixed recipient prevents the endpoint from becoming a general-purpose email relay, but it does not prevent someone from flooding your inbox.

For this tutorial, we’ll require a secret token and accept only POST /notify.

Create a local .dev.vars file:

ALERT_TOKEN=replace-with-a-long-random-secret

Use a genuinely random secret rather than the placeholder.

Do not commit .dev.vars to Git.

Cloudflare recommends keeping sensitive values in secrets rather than ordinary Wrangler configuration variables.

For the deployed Worker, create the same secret using:

npx wrangler secret put ALERT_TOKEN

Wrangler will prompt you to enter its value.

The secret will then be available through env.ALERT_TOKEN.

6. Write the Worker

Replace src/index.ts with:

interface Env {
  EMAIL: {
    send(message: {
      from: string;
      to: string;
      subject: string;
      text: string;
    }): Promise<{ messageId: string }>;
  };

  ALERT_TOKEN: string;
}

export default {
  async fetch(
    request: Request,
    env: Env
  ): Promise<Response> {
    const url = new URL(request.url);

    if (url.pathname !== "/notify") {
      return new Response("Not found", {
        status: 404
      });
    }

    if (request.method !== "POST") {
      return new Response("Method not allowed", {
        status: 405,
        headers: { Allow: "POST" }
      });
    }

    const authorization =
      request.headers.get("Authorization");

    if (
      !env.ALERT_TOKEN ||
      authorization !== `Bearer ${env.ALERT_TOKEN}`
    ) {
      return new Response("Unauthorized", {
        status: 401
      });
    }

    try {
      const result = await env.EMAIL.send({
        from: "[email protected]",
        to: "[email protected]",
        subject: "Build completed",
        text: "Your deployment finished successfully."
      });

      return Response.json({
        accepted: true,
        messageId: result.messageId
      });
    } catch (error: unknown) {
      const code =
        error !== null &&
        typeof error === "object" &&
        "code" in error &&
        typeof error.code === "string"
          ? error.code
          : "UNKNOWN_ERROR";

      console.error("Email sending failed:", code);

      if (code === "E_RECIPIENT_PLAN_RESTRICTED") {
        return Response.json(
          { error: "Recipient is not verified" },
          { status: 403 }
        );
      }

      return Response.json(
        { error: "Email sending failed" },
        { status: 500 }
      );
    }
  }
};

This example uses a minimal TypeScript declaration for the email binding. Cloudflare also provides generated Worker types through Wrangler, which may be preferable in a larger project.

There are several deliberate decisions in the implementation.

The recipient and sender are fixed. The request does not accept an arbitrary email address.

Only POST /notify can initiate sending.

The Authorization header must contain the configured secret.

And the response returns the message ID generated by Cloudflare.

That ID is useful when investigating what happened to a message.

However, accepted: true should not be interpreted as proof that the recipient has already received it.

Email delivery is asynchronous. A successfully accepted message may still be delayed, rejected, or classified as spam by the receiving provider.

For production use, additional controls such as rate limiting, monitoring, and secret rotation are appropriate.

A bearer token is a useful starting point for a personal endpoint, but it should not be the only abuse protection for a high-volume public service.

7. Test locally

Start the Worker:

npx wrangler dev

Cloudflare’s current documentation supports local development with remote Email Sending bindings.

Because our configuration includes:

"remote": true

the Worker can communicate with the actual Cloudflare Email Service while running through Wrangler.

This is worth remembering: a local test can send a real email.

It is not automatically a simulated operation.

Assuming Wrangler starts on port 8787, send a request to:

http://localhost:8787/notify

For Windows PowerShell:

$token = Read-Host "Enter alert token"

Invoke-RestMethod `
  -Method Post `
  -Uri "http://localhost:8787/notify" `
  -Headers @{
    Authorization = "Bearer $token"
  }

Enter the secret from .dev.vars.

If the request is accepted, the response should resemble:

{
  "accepted": true,
  "messageId": "<generated-message-id>"
}

The actual message ID will be assigned by Cloudflare.

Now check the destination inbox.

If the message does not appear, inspect the spam folder and the Email Sending activity logs in Cloudflare Dashboard.

The API response and actual inbox delivery are different stages of the process.

8. Deploy the Worker

Once the local test behaves as expected, deploy it:

npx wrangler deploy

Wrangler will provide the public URL of the Worker.

It may resemble:

https://email-alert-worker.<subdomain>.workers.dev

The endpoint is available at:

https://email-alert-worker.<subdomain>.workers.dev/notify

The exact URL depends on your Cloudflare account and Worker configuration.

Send the same authenticated POST request to the deployed address.

If the deployment reports that the Email Sending binding is missing or unavailable, check that the send_email configuration is present in the environment you deployed.

Also confirm that ALERT_TOKEN exists as a deployed Worker secret. Values stored in .dev.vars are for local development and are not automatically deployed as production secrets.

Common errors and what they mean

Cloudflare Email Service reports specific error codes through the Worker binding.

These are more useful than a generic message saying that email sending failed.

Error Meaning What to check
E_RECIPIENT_PLAN_RESTRICTED Your plan cannot send to the requested unverified address Verify the recipient or use Workers Paid
E_RECIPIENT_NOT_ALLOWED The recipient is outside the binding’s allowed destinations Check destination_address or the allowlist
E_SENDER_NOT_VERIFIED The sender is not permitted by the binding’s sender restrictions Check allowed_sender_addresses if configured
E_SENDER_DOMAIN_NOT_AVAILABLE The sender domain is unavailable for sending Verify its Email Service onboarding and account ownership
E_EMAIL_SENDING_NOT_READY Domain setup has not completed Check onboarding status and retry later
E_RATE_LIMIT_EXCEEDED The service rejected the request due to a rate limit Reduce request frequency and inspect the relevant limits

The distinction between sender errors is worth noting.

A sender address blocked by a binding restriction is not necessarily the same problem as a domain that has never been onboarded to Email Service.

Similarly, an unverified recipient on Workers Free and a recipient excluded by an explicit binding restriction can produce different errors.

Look at the actual error code before changing the configuration.

What if the email never arrives?

A successful send() call does not guarantee inbox delivery.

Cloudflare Email Service provides an Activity log and sending analytics to investigate delivery status.

For messages sent to verified destinations, the November update also brings them into the Email Sending reporting system.

Previously, this type of traffic was associated with Email Routing.

Now those messages can appear in Email Sending activity logs and analytics, with delivery-related events such as message.delivered and message.bounced.

That makes debugging more practical than relying solely on whether a test email appears in the inbox.

What is actually free?

Cloudflare’s announcement contains a distinction that is easy to overlook.

The company did not make unrestricted transactional email available to every free account.

Instead, it enabled Email Sending on Workers Free for verified destination addresses.

Those sends do not count against the ordinary monthly sending quota or daily sending limits.

But the restriction on recipients remains.

For example, this approach is suitable for:

  • Personal deployment and error notifications.
  • Build reports sent to your own inbox.
  • Internal development alerts sent to verified team addresses.
  • Testing the Email Sending integration before production deployment.

It is not suitable, on the Free plan, for sending password-reset emails or registration confirmations to arbitrary application users.

Those recipients are not necessarily verified destination addresses in your Cloudflare account.

For that use case, Cloudflare requires Workers Paid.

There are also other practical costs to distinguish.

The email sends covered by this allowance are free, but you still need a domain for the configured sender, and the Worker remains subject to the applicable Workers plan limits.

Free email delivery does not mean every part of the surrounding application has no cost.

What changed on November 24?

Cloudflare already supported sending messages to verified addresses before this release.

The capability was previously associated with Email Routing.

The November 24 announcement changes its availability and integration within Email Service.

Workers Free users can now onboard sending domains and send to verified destinations using the native Worker binding, REST API, or SMTP.

Those messages are also recorded under Email Sending rather than the previous Email Routing traffic model.

For a developer who only needs to notify their own inbox, the implementation can be small.

Configure a sending domain, verify the destination, add the binding, and call:

await env.EMAIL.send({
  from: "[email protected]",
  to: "[email protected]",
  subject: "Build completed",
  text: "Your deployment finished successfully."
});

The email service handles the sending infrastructure.

The application remains responsible for deciding when a message should be sent and who is allowed to trigger it.

That last responsibility matters even for something as simple as a deployment notification.

An unprotected endpoint can turn a useful feature into a source of unwanted messages.

A fixed recipient, a restricted binding, and authenticated requests provide a much better starting point.

And for a personal notification system, they may be all the infrastructure you actually need before adding more advanced monitoring or automation.

External Sources used for this article

Related Articles

View all →