diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-03-26 00:37:41 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-03-26 00:37:41 +0000 |
| commit | e0dfb55c5457aec489fc084c4567e791b4c65eb1 (patch) | |
| tree | 68543a65d88f5afb3a0202925804103daa91bc6f /lib/mail/mailer.ts | |
3/25 까지의 대표님 작업사항
Diffstat (limited to 'lib/mail/mailer.ts')
| -rw-r--r-- | lib/mail/mailer.ts | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/mail/mailer.ts b/lib/mail/mailer.ts new file mode 100644 index 00000000..e0a90f1e --- /dev/null +++ b/lib/mail/mailer.ts @@ -0,0 +1,31 @@ +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: 465, + secure: true, + auth: { + user: process.env.Email_User_Name, + pass: process.env.Email_Password, + }, +}); + +// Handlebars 템플릿 로더 함수 +function loadTemplate(templateName: string, data: Record<string, any>) { + 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); +} + +handlebars.registerHelper('t', function(key: string, options: any) { + // options.hash에는 Handlebars에서 넘긴 named parameter들(location=location 등)이 들어있음 + return i18next.t(key, options.hash || {}); + }); + +export { transporter, loadTemplate };
\ No newline at end of file |
