mirror of
https://github.com/geoffsee/open-gsio.git
synced 2025-09-08 22:56:46 +00:00
init
This commit is contained in:
41
workers/email/email_worker.js
Normal file
41
workers/email/email_worker.js
Normal file
@@ -0,0 +1,41 @@
|
||||
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@seemueller.io",
|
||||
});
|
||||
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@seemueller.io",
|
||||
"geoff@seemueller.io",
|
||||
msg.asRaw(),
|
||||
);
|
||||
await this.env.SEB.send(message);
|
||||
} catch (e) {
|
||||
return new Response(e.message, { status: 500 });
|
||||
}
|
||||
|
||||
return new Response("Message Sent");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user