Add email worker and use it to send email from pages function
Some checks failed
release / Publish to Cloudflare Pages (push) Failing after 1m17s

This commit is contained in:
2025-02-03 17:00:59 +10:30
parent 73a4ee7df4
commit d487f7ecb7
11 changed files with 2426 additions and 38 deletions

View File

@@ -0,0 +1,18 @@
import { EmailMessage } from "cloudflare:email";
import { WorkerEntrypoint } from "cloudflare:workers";
export default class SendEmailWorker extends WorkerEntrypoint<Env> {
async sendEmail(rawMessage: string): Promise<Response> {
try {
const cfMessage = new EmailMessage(
"contact@michaelpivato.dev",
"contact@michaelpivato.dev",
rawMessage
);
await this.env.SEB.send(cfMessage);
} catch (e) {
return new Response((e as Error).message);
}
return new Response();
}
}