summaryrefslogtreecommitdiff
path: root/lib/mail/mailer.ts
blob: 329e2e520bac8bacfd2192aea7994ba57257155f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import nodemailer from 'nodemailer';
import handlebars from 'handlebars';
import fs from 'fs';
import path from 'path';
import i18next from 'i18next';

// Nodemailer Transporter 생성
const transporter = nodemailer.createTransport({
  host: process.env.Email_Host,
  port: parseInt(process.env.Email_Port || '465'),
  secure: process.env.Email_Secure === 'true',
  auth: {
    user: process.env.Email_User_Name,
    pass: process.env.Email_Password,
  },
});

// 템플릿 로더 함수 - 단순화된 버전
function loadTemplate(templateName: string, data: Record<string, unknown>) {
  const templatePath = path.join(process.cwd(), 'lib', 'mail', 'templates', `${templateName}.hbs`);
  const source = fs.readFileSync(templatePath, 'utf8');
  const template = handlebars.compile(source);
  return template(data);
}

// i18next 헬퍼 등록
handlebars.registerHelper('t', function(key: string, options: { hash?: Record<string, unknown> }) {
  // options.hash에는 Handlebars에서 넘긴 named parameter들이 들어있음
  return i18next.t(key, options.hash || {});
});

export { transporter, loadTemplate };