ses-mail-protector
Version:
Node.js library for AWS SES email sending with bounce & complaint handling using MongoDB.
34 lines (28 loc) • 904 B
JavaScript
require("dotenv").config();
const { SendEmailCommand } = require("../sesClient.js");
const ses = require("../sesClient.js");
async function sendAdminNotification({ subject, to, email, reason, details }) {
const body = `
<h2>SES Notification</h2>
<p><b>Email:</b> ${email}</p>
<p><b>Reason:</b> ${reason}</p>
<pre>${JSON.stringify(details, null, 2)}</pre>
`;
const command = new SendEmailCommand({
Destination: { ToAddresses: [to] },
Content: {
Simple: {
Subject: { Data: subject },
Body: { Html: { Data: body } },
},
},
FromEmailAddress: process.env.SES_FROM_ADDRESS,
});
try {
await ses.send(command);
// console.log(`📩 Admin notified: ${subject} (${email})`);
} catch (err) {
console.error("❌ Failed to notify admin:", err);
}
}
module.exports = { sendAdminNotification };