Anzeige-Name ueberall umgestellt: - index.html title, Login-H1, TopNav, SuperAdmin-Header - Mail-Subject, HTML-Body, Default-MAIL_FROM - PWA Manifest name (short_name: Dockly-Pfand wegen Laengen-Limit)
68 lines
3.1 KiB
JavaScript
68 lines
3.1 KiB
JavaScript
import nodemailer from 'nodemailer';
|
|
import { Resend } from 'resend';
|
|
|
|
const FROM = process.env.MAIL_FROM || 'Dockly-Pfandsystem Demo <demo@dockly.de>';
|
|
|
|
let transporter = null;
|
|
if (process.env.SMTP_HOST && process.env.SMTP_USER && process.env.SMTP_PASS) {
|
|
transporter = nodemailer.createTransport({
|
|
host: process.env.SMTP_HOST,
|
|
port: parseInt(process.env.SMTP_PORT || '587'),
|
|
secure: (process.env.SMTP_SECURE || 'false') === 'true', // 587 = STARTTLS (secure=false)
|
|
auth: {
|
|
user: process.env.SMTP_USER,
|
|
pass: process.env.SMTP_PASS,
|
|
},
|
|
});
|
|
console.log('[mail] SMTP transport aktiv:', process.env.SMTP_HOST);
|
|
}
|
|
|
|
const resend = process.env.RESEND_API_KEY ? new Resend(process.env.RESEND_API_KEY) : null;
|
|
|
|
async function sendMail({ to, subject, html }) {
|
|
if (transporter) {
|
|
const info = await transporter.sendMail({ from: FROM, to, subject, html });
|
|
console.log('[mail] SMTP sent:', to, 'msgId:', info.messageId);
|
|
return { provider: 'smtp', messageId: info.messageId, accepted: info.accepted, rejected: info.rejected };
|
|
}
|
|
if (resend) {
|
|
const r = await resend.emails.send({ from: FROM, to, subject, html });
|
|
console.log('[mail] Resend sent:', to, 'id:', r.data?.id);
|
|
return { provider: 'resend', id: r.data?.id, error: r.error };
|
|
}
|
|
console.log('[mail-dev] (kein Provider konfiguriert) ->', to, subject);
|
|
return { dev: true };
|
|
}
|
|
|
|
export async function sendDemoInviteMail({ to, name, slug, password, loginUrl, days }) {
|
|
const html = `
|
|
<div style="font-family:system-ui,Segoe UI,Helvetica,Arial,sans-serif;max-width:560px;margin:auto">
|
|
<h2 style="color:#051e23">Willkommen im Dockly-Pfandsystem-Demo</h2>
|
|
<p>Hallo ${name},</p>
|
|
<p>dein <strong>${days}-Tage Demo-Zugang</strong> ist bereit. Du kannst alle Funktionen
|
|
in Ruhe testen und eigene Beispieldaten anlegen.</p>
|
|
<div style="background:#f1f7f8;border:1px solid #b9d2d7;border-radius:8px;padding:16px;margin:16px 0">
|
|
<p style="margin:4px 0"><strong>Login-URL:</strong> <a href="${loginUrl}">${loginUrl}</a></p>
|
|
<p style="margin:4px 0"><strong>E-Mail:</strong> ${to}</p>
|
|
<p style="margin:4px 0"><strong>Passwort:</strong> <code>${password}</code></p>
|
|
<p style="margin:4px 0"><strong>Tenant-Kennung:</strong> ${slug}</p>
|
|
</div>
|
|
<p>Bitte aendere dein Passwort nach dem ersten Login.</p>
|
|
<p style="color:#64748b;font-size:12px">Diese Mail wurde automatisch versandt vom Dockly-Pfandsystem-Demo-Portal.</p>
|
|
</div>`;
|
|
return sendMail({ to, subject: `Dein Dockly-Pfandsystem-Demo-Zugang (${days} Tage)`, html });
|
|
}
|
|
|
|
// Test-Endpoint Helper
|
|
export async function sendTestMail(to) {
|
|
const html = `
|
|
<div style="font-family:system-ui,Segoe UI,Helvetica,Arial,sans-serif;max-width:560px;margin:auto">
|
|
<h2 style="color:#051e23">Dockly-Pfandsystem Demo - SMTP-Test</h2>
|
|
<p>Diese Test-Mail bestaetigt, dass der Mail-Versand ueber
|
|
<code>${process.env.SMTP_HOST || 'kein SMTP'}</code> funktioniert.</p>
|
|
<p>Absender: <code>${FROM}</code></p>
|
|
<p>Zeitstempel: ${new Date().toISOString()}</p>
|
|
</div>`;
|
|
return sendMail({ to, subject: 'Dockly-Pfandsystem Demo - SMTP-Test', html });
|
|
}
|