Add email worker and use it to send email from pages function
Some checks failed
release / Publish to Cloudflare Pages (push) Failing after 1m17s
Some checks failed
release / Publish to Cloudflare Pages (push) Failing after 1m17s
This commit is contained in:
18
contact-email-worker/src/index.ts
Normal file
18
contact-email-worker/src/index.ts
Normal 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user