const nodemailer = require("nodemailer"); async function sendReportMail({ smtpConfig, subject, html, text }) { if (!smtpConfig.enabled) { return { skipped: true, reason: "SMTP_ENABLED=false" }; } if ( !smtpConfig.host || !smtpConfig.port || !smtpConfig.user || !smtpConfig.pass || !smtpConfig.from || smtpConfig.to.length === 0 ) { throw new Error( "SMTP ist aktiviert, aber SMTP_HOST/PORT/USER/PASS/FROM/TO sind nicht vollstaendig gesetzt." ); } const transport = nodemailer.createTransport({ host: smtpConfig.host, port: smtpConfig.port, secure: smtpConfig.secure, auth: { user: smtpConfig.user, pass: smtpConfig.pass, }, }); const info = await transport.sendMail({ from: smtpConfig.from, to: smtpConfig.to.join(", "), subject, text, html, }); return { skipped: false, messageId: info.messageId }; } module.exports = { sendReportMail, };