Co-authored-by: Cursor <[email protected]>
This commit is contained in:
lejay
2026-05-28 07:20:38 +02:00
co-authored by Cursor
parent 6923c319a1
commit 6c0d7e47b8
81 changed files with 21780 additions and 2986 deletions
+35
View File
@@ -0,0 +1,35 @@
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 });
}