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:
@@ -98,6 +98,10 @@ Everything in `public/` is published by `npm run build`; delete `standalone.html
|
|||||||
`server/` is a small Express + SQL service that receives the webhook events
|
`server/` is a small Express + SQL service that receives the webhook events
|
||||||
(`POST /api/webhook`). Point `VITE_CRM_WEBHOOK_URL` at it and set `VITE_CRM_PROVIDER=webhook`.
|
(`POST /api/webhook`). Point `VITE_CRM_WEBHOOK_URL` at it and set `VITE_CRM_PROVIDER=webhook`.
|
||||||
|
|
||||||
|
It also emails a notification to `NOTIFY_EMAIL` (see `server/.env.example`) every time a
|
||||||
|
visitor registers or downloads an ROI report. Set `SMTP_HOST`/`SMTP_USER`/`SMTP_PASSWORD`
|
||||||
|
to enable it; leave `SMTP_HOST` blank to disable.
|
||||||
|
|
||||||
## Project map
|
## Project map
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -12,3 +12,12 @@ DB_CA_PATH=
|
|||||||
ALLOWED_ORIGIN=https://toolkit.blackdice.ai
|
ALLOWED_ORIGIN=https://toolkit.blackdice.ai
|
||||||
|
|
||||||
PORT=8080
|
PORT=8080
|
||||||
|
|
||||||
|
# SMTP settings used to notify the team whenever a visitor submits data
|
||||||
|
# (registration or ROI report download). Leave blank to disable notifications.
|
||||||
|
SMTP_HOST=
|
||||||
|
SMTP_PORT=587
|
||||||
|
SMTP_USER=
|
||||||
|
SMTP_PASSWORD=
|
||||||
|
SMTP_FROM=
|
||||||
|
NOTIFY_EMAIL=mark.mullings@blackdice.ai
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import 'dotenv/config';
|
|||||||
import cors from 'cors';
|
import cors from 'cors';
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
import { pool } from './db.js';
|
import { pool } from './db.js';
|
||||||
|
import { notifySubmission } from './mailer.js';
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
@@ -35,6 +36,7 @@ app.post('/api/webhook', async (req, res) => {
|
|||||||
} else {
|
} else {
|
||||||
return res.status(400).json({ ok: false, error: `Unknown event: ${event}` });
|
return res.status(400).json({ ok: false, error: `Unknown event: ${event}` });
|
||||||
}
|
}
|
||||||
|
notifySubmission({ event, lead, roi, submittedAt }).catch((err) => console.error('[mail] notify failed:', err));
|
||||||
res.json({ ok: true });
|
res.json({ ok: true });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('[db] write failed:', err);
|
console.error('[db] write failed:', err);
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Generated
+11
-1
@@ -11,7 +11,8 @@
|
|||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"dotenv": "^16.4.5",
|
"dotenv": "^16.4.5",
|
||||||
"express": "^4.21.2",
|
"express": "^4.21.2",
|
||||||
"mysql2": "^3.11.5"
|
"mysql2": "^3.11.5",
|
||||||
|
"nodemailer": "^10.1.7"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@types/node": {
|
"node_modules/@types/node": {
|
||||||
@@ -661,6 +662,15 @@
|
|||||||
"node": ">= 0.6"
|
"node": ">= 0.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/nodemailer": {
|
||||||
|
"version": "10.1.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-10.1.7.tgz",
|
||||||
|
"integrity": "sha512-OQa6FDln5fLttmqSbjDiRYvFDOFNrBqfiOwHPlEbURil3b+vPB1v8xpi+Sp46drzNDlsTnNsS502vthmz56r4w==",
|
||||||
|
"license": "MIT-0",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=20.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/object-assign": {
|
"node_modules/object-assign": {
|
||||||
"version": "4.1.1",
|
"version": "4.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
|
||||||
|
|||||||
+2
-1
@@ -11,6 +11,7 @@
|
|||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"dotenv": "^16.4.5",
|
"dotenv": "^16.4.5",
|
||||||
"express": "^4.21.2",
|
"express": "^4.21.2",
|
||||||
"mysql2": "^3.11.5"
|
"mysql2": "^3.11.5",
|
||||||
|
"nodemailer": "^10.1.7"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user