Centralize notification templates
This commit is contained in:
@@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user