Files
apex/server/services/mailer.js
T
lejayandCursor 6c0d7e47b8 v2.0
Co-authored-by: Cursor <[email protected]>
2026-05-28 07:20:38 +02:00

36 lines
865 B
JavaScript

import nodemailer from 'nodemailer';
let transporter = null;
function getTransporter() {
if (transporter) return transporter;
const host = process.env.SMTP_HOST;
const port = Number(process.env.SMTP_PORT) || 587;
const user = process.env.SMTP_USER;
const pass = process.env.SMTP_PASS;
if (!host || !user || !pass) {
throw new Error('SMTP configuration manquante (SMTP_HOST, SMTP_USER, SMTP_PASS)');
}
transporter = nodemailer.createTransport({
host,
port,
secure: port === 465,
auth: { user, pass }
});
return transporter;
}
/**
* Send an email.
* @param {{ to: string, subject: string, html: string }} options
*/
export async function sendEmail({ to, subject, html }) {
const from = process.env.SMTP_FROM || process.env.SMTP_USER;
const t = getTransporter();
await t.sendMail({ from, to, subject, html });
}