Updated Logging System to Include Application Logs
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
const nodemailer = require('nodemailer');
|
||||
const { all, audit, now, run } = require('../db');
|
||||
const { logEvent } = require('../logger');
|
||||
|
||||
function readSettings() {
|
||||
const rows = all('SELECT key, value FROM app_settings');
|
||||
@@ -95,13 +96,20 @@ async function sendMail({ to, subject, html, text }) {
|
||||
throw Object.assign(new Error('No recipients are configured'), { status: 400 });
|
||||
}
|
||||
const transport = getTransport();
|
||||
return transport.sendMail({
|
||||
from: c.from || c.user,
|
||||
to: recipients.join(', '),
|
||||
subject,
|
||||
html,
|
||||
text
|
||||
});
|
||||
try {
|
||||
const info = await transport.sendMail({
|
||||
from: c.from || c.user,
|
||||
to: recipients.join(', '),
|
||||
subject,
|
||||
html,
|
||||
text
|
||||
});
|
||||
logEvent('smtp', `Email sent: "${subject}" to ${recipients.length} recipient(s)`, { subject, recipients: recipients.length, host: c.host, messageId: info.messageId });
|
||||
return info;
|
||||
} catch (error) {
|
||||
logEvent('smtp', `Email send failed: "${subject}" — ${error.message}`, { subject, recipients: recipients.length, host: c.host }, 'error');
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async function sendTestEmail(to, userId) {
|
||||
|
||||
Reference in New Issue
Block a user