yolo_web/dist/mail.js

48 lines
1.5 KiB
JavaScript
Raw Permalink Normal View History

2023-12-14 20:31:36 +00:00
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.sendMail = void 0;
const nodemailer_1 = __importDefault(require("nodemailer"));
const log_1 = require("./log");
const from = process.env['MAIL_FROM'];
const smtp = process.env['MAIL_SMTP'];
const port = typeof process.env['MAIL_SMTP_PORT'] !== 'undefined' ? 25 : parseInt(process.env['MAIL_SMTP_PORT'], 10);
let transporter = null;
const log = (0, log_1.createLog)('mail');
if (typeof from !== 'undefined' && from !== null && from !== '' &&
typeof smtp !== 'undefined' && smtp !== null && smtp !== '') {
transporter = nodemailer_1.default.createTransport({
host: smtp,
port,
secure: false,
tls: { rejectUnauthorized: false }
});
}
async function sendMail(to, subject, body) {
if (transporter !== null) {
try {
await transporter.sendMail({
from,
to,
subject,
html: body
});
log.info(`Sent email "${subject}"`);
}
catch (err) {
log.error(`Error sending email "${subject}"`);
log.error(err);
return false;
}
}
else {
log.warn(`Email not configured, not sending "${subject}"`);
return false;
}
return true;
}
exports.sendMail = sendMail;
module.exports = { sendMail };
//# sourceMappingURL=mail.js.map