Centralize notification templates

This commit is contained in:
Ruslan Bakiev
2026-04-06 15:04:45 +07:00
parent 0f8f64a8a2
commit 44c24c4abd
5 changed files with 337 additions and 66 deletions

View File

@@ -1,4 +1,5 @@
import nodemailer from 'nodemailer';
import { buildLoginCodeEmailTemplate } from './notification-templates.js';
let cachedTransporter = null;
@@ -57,13 +58,13 @@ function getTransporter() {
export async function sendLoginCodeEmail({ to, code, expiresAt }) {
const { from } = getSmtpConfig();
const transporter = getTransporter();
const expiresText = new Date(expiresAt).toLocaleString('ru-RU', { hour12: false });
const template = buildLoginCodeEmailTemplate({ code, expiresAt });
await transporter.sendMail({
from,
to,
subject: 'Код входа в личный кабинет Fregat',
text: `Код входа: ${code}\nДействует до: ${expiresText}`,
html: `<p>Код входа: <b>${code}</b></p><p>Действует до: ${expiresText}</p>`,
subject: template.subject,
text: template.text,
html: template.html,
});
}