mirror of
https://github.com/geoffsee/open-gsio.git
synced 2025-09-08 22:56:46 +00:00

Replaced Wrangler TOML files with JSON configuration for email and analytics workers, updating compatibility dates and maintaining existing settings. Updated email metadata and replaced hardcoded email addresses with example addresses for better abstraction. Adjusted deployment scripts in `package.json` to align with the new worker structure.
42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
import { WorkerEntrypoint } from "cloudflare:workers";
|
|
import { createMimeMessage } from "mimetext";
|
|
import { EmailMessage } from "cloudflare:email";
|
|
|
|
export default class EmailWorker extends WorkerEntrypoint {
|
|
async fetch(req, env, ctx) {
|
|
return new Response(undefined, { status: 200 });
|
|
}
|
|
|
|
async sendMail({
|
|
plaintextMessage = `You must have wondered where I've been.`,
|
|
to,
|
|
}) {
|
|
const msg = createMimeMessage();
|
|
msg.setSender({
|
|
name: "New Website Contact",
|
|
addr: "contact@example.com",
|
|
});
|
|
console.log("Recipient:", to);
|
|
// msg.setRecipient(to);
|
|
msg.setRecipient(to);
|
|
msg.setSubject("New Contact Request: Website");
|
|
msg.addMessage({
|
|
contentType: "text/plain",
|
|
data: plaintextMessage,
|
|
});
|
|
|
|
try {
|
|
const message = new EmailMessage(
|
|
"contact@example.com",
|
|
"team@example.com",
|
|
msg.asRaw(),
|
|
);
|
|
await this.env.SEB.send(message);
|
|
} catch (e) {
|
|
return new Response(e.message, { status: 500 });
|
|
}
|
|
|
|
return new Response("Message Sent");
|
|
}
|
|
}
|