Email mark.mullings@blackdice.ai on every toolkit submission

Adds an SMTP-based notification (server/mailer.js) that fires whenever
a visitor registers or downloads an ROI report, configured via
NOTIFY_EMAIL/SMTP_* env vars.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-10-19 16:23:31 +05:00
co-authored by Claude Sonnet 5
parent 214efa2bce
commit 28041e6d15
6 changed files with 89 additions and 2 deletions
+61
View File
@@ -0,0 +1,61 @@
import nodemailer from 'nodemailer';
const { SMTP_HOST, SMTP_PORT = '587', SMTP_USER, SMTP_PASSWORD, SMTP_FROM, NOTIFY_EMAIL } = process.env;
const transporter = SMTP_HOST
? nodemailer.createTransport({
host: SMTP_HOST,
port: Number(SMTP_PORT),
secure: Number(SMTP_PORT) === 465,
auth: SMTP_USER ? { user: SMTP_USER, pass: SMTP_PASSWORD } : undefined,
})
: null;
/** Fire-and-forget notification sent whenever a visitor submits data. Never blocks the request. */
export async function notifySubmission({ event, lead, roi, submittedAt }) {
if (!transporter || !NOTIFY_EMAIL) {
console.info('[mail] SMTP not configured — skipping submission notification');
return;
}
const subject =
event === 'roi_report_downloaded'
? `ROI report downloaded — ${lead.email}`
: `New toolkit registration — ${lead.email}`;
const lines = [
`Event: ${event}`,
`Submitted at: ${submittedAt || new Date().toISOString()}`,
'',
`Name: ${[lead.first, lead.last].filter(Boolean).join(' ') || '—'}`,
`Email: ${lead.email}`,
`Company: ${lead.company || '—'}`,
`Title: ${lead.title || '—'}`,
`Region: ${lead.region || '—'}`,
`Subscriber band: ${lead.subs || '—'}`,
];
if (roi?.results) {
lines.push(
'',
'ROI results:',
` Total: ${roi.formatted?.total ?? '—'}`,
` Bandwidth savings: ${roi.formatted?.bw ?? '—'}`,
` Support calls savings: ${roi.formatted?.calls ?? '—'}`,
` Churn savings: ${roi.formatted?.churn ?? '—'}`,
` Equipment savings: ${roi.formatted?.equip ?? '—'}`,
` DDoS savings: ${roi.formatted?.ddos ?? '—'}`
);
}
try {
await transporter.sendMail({
from: SMTP_FROM || SMTP_USER,
to: NOTIFY_EMAIL,
subject,
text: lines.join('\n'),
});
} catch (err) {
console.error('[mail] failed to send submission notification:', err);
}
}