From eefea9711f8be485c78e0a337f7b62567b5e4298 Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Tue, 14 Oct 2025 07:10:57 +0000 Subject: [PATCH] Create email service cgen-85300e547cfb4c0d8108b744f0273088 --- server/email.ts | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 server/email.ts diff --git a/server/email.ts b/server/email.ts new file mode 100644 index 00000000..c802a802 --- /dev/null +++ b/server/email.ts @@ -0,0 +1,66 @@ +import { Resend } from "resend"; + +const resendApiKey = process.env.RESEND_API_KEY; +const defaultFromAddress = process.env.RESEND_FROM_EMAIL ?? "AeThex OS "; +const verifySupportEmail = process.env.VERIFY_SUPPORT_EMAIL ?? "support@aethex.biz"; + +const resendClient = resendApiKey ? new Resend(resendApiKey) : null; + +export const emailService = { + get isConfigured() { + return Boolean(resendClient); + }, + + async sendVerificationEmail(params: { + to: string; + verificationUrl: string; + fullName?: string | null; + }) { + if (!resendClient) { + throw new Error("Email service is not configured. Set RESEND_API_KEY."); + } + + const { to, verificationUrl, fullName } = params; + const safeName = fullName?.trim() || "there"; + + const subject = "Verify your AeThex account"; + const previewText = "Confirm your AeThex account to access the dashboard."; + + const html = ` +
+

Welcome to AeThex, ${safeName}!

+

Click the button below to verify your account and unlock your personal dashboard.

+

+ Verify my account +

+

If the button does not work, paste this link into your browser:

+

${verificationUrl}

+
+

+ Didnt create an account? Please ignore this email or contact ${verifySupportEmail}. +

+
+ `; + + const text = [`Welcome to AeThex, ${safeName}!`, "", + "Use the link below to verify your account:", + verificationUrl, + "", + `If you didn't request this, contact us at ${verifySupportEmail}.`, + ].join("\n"); + + await resendClient.emails.send({ + from: defaultFromAddress, + to, + subject, + html, + text, + headers: { + "X-AeThex-Email": "verification", + "X-Entity-Ref-ID": verificationUrl.slice(-24), + }, + tags: [{ name: "template", value: "auth-verification" }], + reply_to: verifySupportEmail, + }); + }, +};