UNPKG

nodly

Version:

Nodly is an interactive CLI for scaffolding modern Node.js/Express.js backend projects with instant setup for databases, mailers, queues, sockets, and more. Skip boilerplate and start building features fast.

27 lines (23 loc) 612 B
import { getMailer, initMailer } from "../config/mailers/nodemailer.js"; let mailerInitialized = false; export const sendEmail = async ({ to, subject, html, text }) => { try { if (!mailerInitialized) { initMailer(); mailerInitialized = true; } const transporter = getMailer(); const info = await transporter.sendMail({ from: `"User" <user@example.com>`, to, subject, text, html, }); console.log(`Email sent: ${info.messageId}`); return info; } catch (error) { console.error("Failed to send email:", error); throw error; } };