UNPKG

@maizzle/framework

Version:

Maizzle is a framework that helps you quickly build HTML emails with Tailwind CSS.

40 lines (39 loc) 1.28 kB
import nodemailer from "nodemailer"; //#region src/server/email.ts async function sendEmail(payload, config, templateConfig) { const emailConfig = templateConfig.server?.email ?? config.server?.email; let transport; let isEthereal = false; if (emailConfig?.transport) transport = nodemailer.createTransport(emailConfig.transport); else { const testAccount = await nodemailer.createTestAccount(); transport = nodemailer.createTransport({ host: "smtp.ethereal.email", port: 587, secure: false, auth: { user: testAccount.user, pass: testAccount.pass } }); isEthereal = true; } const from = emailConfig?.from ?? "Maizzle <maizzle@ethereal.email>"; const info = await transport.sendMail({ from, to: payload.to.join(", "), subject: payload.subject || "Test email", html: payload.html, text: payload.text || void 0 }); const previewUrl = isEthereal ? nodemailer.getTestMessageUrl(info) || void 0 : void 0; const recipient = payload.to.length === 1 ? payload.to[0] : `${payload.to.length} recipients`; return { success: true, message: isEthereal ? "Sent via Ethereal" : `Sent to ${recipient}`, previewUrl: typeof previewUrl === "string" ? previewUrl : void 0 }; } //#endregion export { sendEmail }; //# sourceMappingURL=email.js.map