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.
26 lines (20 loc) • 628 B
JavaScript
import nodemailer from "nodemailer";
import dotenv from "dotenv";
dotenv.config();
let transporter;
export const initMailer = () => {
transporter = nodemailer.createTransport({
host: process.env.MAIL_HOST,
port: parseInt(process.env.MAIL_PORT) || 587,
secure: process.env.MAIL_SECURE === "true", // true for 465, false for 587
auth: {
user: process.env.MAIL_USER,
pass: process.env.MAIL_PASS,
},
});
console.log("Mailer initialized");
};
export const getMailer = () => {
if (!transporter) throw new Error("Mailer not initialized. Call initMailer() first.");
return transporter;
};