Cloudflare Workers

Send email from Workers and Pages Functions.

Send email from Workers and Pages Functions.

Install

npm i resent.one

Set RESENT_API_KEY in your server environment. Keep the key off the client.

Send an email

import { Resent } from "resent.one";
export default {
async fetch(request, env) {
if (request.method !== "POST") {
return new Response("Method not allowed", { status: 405 });
}
const resent = new Resent(env.RESENT_API_KEY);
const result = await resent.emails.send({
from: "Acme <noreply@yourdomain.com>",
to: "you@example.com",
subject: "Hello from Cloudflare Workers",
html: "<strong>It works!</strong>",
});
return Response.json(result);
},
};

Next steps